Changes in src/molecule.cpp [822f01:bf3817]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
r822f01 rbf3817 5 5 */ 6 6 7 // include config.h 7 8 #ifdef HAVE_CONFIG_H 8 9 #include <config.h> … … 24 25 #include "element.hpp" 25 26 #include "graph.hpp" 26 #include " helpers.hpp"27 #include "Helpers/helpers.hpp" 27 28 #include "leastsquaremin.hpp" 28 29 #include "linkedcell.hpp" 29 30 #include "lists.hpp" 30 #include " log.hpp"31 #include "Helpers/Log.hpp" 31 32 #include "molecule.hpp" 32 33 … … 34 35 #include "stackclass.hpp" 35 36 #include "tesselation.hpp" 36 #include " vector.hpp"37 #include " Matrix.hpp"37 #include "LinearAlgebra/Vector.hpp" 38 #include "LinearAlgebra/Matrix.hpp" 38 39 #include "World.hpp" 39 40 #include "Box.hpp" 40 #include " Plane.hpp"41 #include "LinearAlgebra/Plane.hpp" 41 42 #include "Exceptions/LinearDependenceException.hpp" 42 43 … … 157 158 atomIds.erase( atom->getId() ); 158 159 atoms.remove( atom ); 159 formula-=atom-> type;160 formula-=atom->getType(); 160 161 atom->removeFromMolecule(); 161 162 return iter; … … 169 170 atomIds.erase( key->getId() ); 170 171 atoms.remove( key ); 171 formula-=key-> type;172 formula-=key->getType(); 172 173 key->removeFromMolecule(); 173 174 } … … 191 192 if (res.second) { // push atom if went well 192 193 atoms.push_back(key); 193 formula+=key-> type;194 formula+=key->getType(); 194 195 return pair<iterator,bool>(molecule::iterator(--end()),res.second); 195 196 } else { … … 212 213 if (pointer != NULL) { 213 214 pointer->sort = &pointer->nr; 214 if (pointer-> type!= NULL) {215 formula += pointer-> type;216 if (pointer-> type->Z != 1)215 if (pointer->getType() != NULL) { 216 formula += pointer->getType(); 217 if (pointer->getType()->Z != 1) 217 218 NoNonHydrogen++; 218 219 if(pointer->getName() == "Unknown"){ 219 220 stringstream sstr; 220 sstr << pointer-> type->getSymbol() << pointer->nr+1;221 sstr << pointer->getType()->getSymbol() << pointer->nr+1; 221 222 pointer->setName(sstr.str()); 222 223 } … … 239 240 if (pointer != NULL) { 240 241 atom *walker = pointer->clone(); 241 formula += walker-> type;242 formula += walker->getType(); 242 243 walker->setName(pointer->getName()); 243 244 walker->nr = last_atom++; // increase number within molecule 244 245 insert(walker); 245 if ((pointer-> type != NULL) && (pointer->type->Z != 1))246 if ((pointer->getType() != NULL) && (pointer->getType()->Z != 1)) 246 247 NoNonHydrogen++; 247 248 retval=walker; … … 301 302 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; 302 303 // create vector in direction of bond 303 InBondvector = TopReplacement-> x - TopOrigin->x;304 InBondvector = TopReplacement->getPosition() - TopOrigin->getPosition(); 304 305 bondlength = InBondvector.Norm(); 305 306 … … 313 314 Orthovector1.Zero(); 314 315 for (int i=NDIM;i--;) { 315 l = TopReplacement-> x[i] - TopOrigin->x[i];316 l = TopReplacement->at(i) - TopOrigin->at(i); 316 317 if (fabs(l) > BondDistance) { // is component greater than bond distance 317 318 Orthovector1[i] = (l < 0) ? -1. : +1.; … … 328 329 InBondvector.Normalize(); 329 330 // get typical bond length and store as scale factor for later 330 ASSERT(TopOrigin-> type!= NULL, "AddHydrogenReplacementAtom: element of TopOrigin is not given.");331 BondRescale = TopOrigin-> type->HBondDistance[TopBond->BondDegree-1];331 ASSERT(TopOrigin->getType() != NULL, "AddHydrogenReplacementAtom: element of TopOrigin is not given."); 332 BondRescale = TopOrigin->getType()->HBondDistance[TopBond->BondDegree-1]; 332 333 if (BondRescale == -1) { 333 334 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl); … … 343 344 case 1: 344 345 FirstOtherAtom = World::getInstance().createAtom(); // new atom 345 FirstOtherAtom-> type = elemente->FindElement(1); // element is Hydrogen346 FirstOtherAtom-> v = TopReplacement->v; // copy velocity346 FirstOtherAtom->setType(1); // element is Hydrogen 347 FirstOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 347 348 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 348 if (TopReplacement-> type->Z == 1) { // neither rescale nor replace if it's already hydrogen349 if (TopReplacement->getType()->Z == 1) { // neither rescale nor replace if it's already hydrogen 349 350 FirstOtherAtom->father = TopReplacement; 350 351 BondRescale = bondlength; … … 353 354 } 354 355 InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length 355 FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ... 356 FirstOtherAtom->x += InBondvector; // ... and add distance vector to replacement atom 356 FirstOtherAtom->setPosition(TopOrigin->getPosition() + InBondvector); // set coordination to origin and add distance vector to replacement atom 357 357 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); 358 358 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; … … 387 387 // determine the plane of these two with the *origin 388 388 try { 389 Orthovector1 =Plane(TopOrigin-> x, FirstOtherAtom->x, SecondOtherAtom->x).getNormal();389 Orthovector1 =Plane(TopOrigin->getPosition(), FirstOtherAtom->getPosition(), SecondOtherAtom->getPosition()).getNormal(); 390 390 } 391 391 catch(LinearDependenceException &excp){ … … 408 408 FirstOtherAtom = World::getInstance().createAtom(); 409 409 SecondOtherAtom = World::getInstance().createAtom(); 410 FirstOtherAtom-> type = elemente->FindElement(1);411 SecondOtherAtom-> type = elemente->FindElement(1);412 FirstOtherAtom-> v = TopReplacement->v; // copy velocity410 FirstOtherAtom->setType(1); 411 SecondOtherAtom->setType(1); 412 FirstOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 413 413 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 414 SecondOtherAtom-> v = TopReplacement->v; // copy velocity414 SecondOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 415 415 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 416 416 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father 417 417 SecondOtherAtom->father = NULL; // we are just an added hydrogen with no father 418 bondangle = TopOrigin-> type->HBondAngle[1];418 bondangle = TopOrigin->getType()->HBondAngle[1]; 419 419 if (bondangle == -1) { 420 420 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl); … … 430 430 // Log() << Verbose(0) << endl; 431 431 // Log() << Verbose(3) << "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle) << endl; 432 FirstOtherAtom-> x.Zero();433 SecondOtherAtom-> x.Zero();432 FirstOtherAtom->Zero(); 433 SecondOtherAtom->Zero(); 434 434 for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction) 435 FirstOtherAtom-> x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle));436 SecondOtherAtom-> x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle));437 } 438 FirstOtherAtom-> x *= BondRescale; // rescale by correct BondDistance439 SecondOtherAtom-> x *= BondRescale;435 FirstOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle))); 436 SecondOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle))); 437 } 438 FirstOtherAtom->Scale(BondRescale); // rescale by correct BondDistance 439 SecondOtherAtom->Scale(BondRescale); 440 440 //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 441 for(int i=NDIM;i--;) { // and make relative to origin atom 442 FirstOtherAtom->x[i] += TopOrigin->x[i]; 443 SecondOtherAtom->x[i] += TopOrigin->x[i]; 444 } 441 *FirstOtherAtom += TopOrigin->getPosition(); 442 *SecondOtherAtom += TopOrigin->getPosition(); 445 443 // ... and add to molecule 446 444 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); … … 464 462 SecondOtherAtom = World::getInstance().createAtom(); 465 463 ThirdOtherAtom = World::getInstance().createAtom(); 466 FirstOtherAtom-> type = elemente->FindElement(1);467 SecondOtherAtom-> type = elemente->FindElement(1);468 ThirdOtherAtom-> type = elemente->FindElement(1);469 FirstOtherAtom-> v = TopReplacement->v; // copy velocity464 FirstOtherAtom->setType(1); 465 SecondOtherAtom->setType(1); 466 ThirdOtherAtom->setType(1); 467 FirstOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 470 468 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 471 SecondOtherAtom-> v = TopReplacement->v; // copy velocity469 SecondOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 472 470 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 473 ThirdOtherAtom-> v = TopReplacement->v; // copy velocity471 ThirdOtherAtom->AtomicVelocity = TopReplacement->AtomicVelocity; // copy velocity 474 472 ThirdOtherAtom->FixedIon = TopReplacement->FixedIon; 475 473 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father … … 494 492 495 493 // create correct coordination for the three atoms 496 alpha = (TopOrigin-> type->HBondAngle[2])/180.*M_PI/2.; // retrieve triple bond angle from database494 alpha = (TopOrigin->getType()->HBondAngle[2])/180.*M_PI/2.; // retrieve triple bond angle from database 497 495 l = BondRescale; // desired bond length 498 496 b = 2.*l*sin(alpha); // base length of isosceles triangle … … 505 503 factors[1] = f; 506 504 factors[2] = 0.; 507 FirstOtherAtom-> x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);505 FirstOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 508 506 factors[1] = -0.5*f; 509 507 factors[2] = g; 510 SecondOtherAtom-> x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);508 SecondOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 511 509 factors[2] = -g; 512 ThirdOtherAtom-> x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);510 ThirdOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 513 511 514 512 // rescale each to correct BondDistance … … 518 516 519 517 // and relative to *origin atom 520 FirstOtherAtom->x += TopOrigin->x;521 SecondOtherAtom->x += TopOrigin->x;522 ThirdOtherAtom->x += TopOrigin->x;518 *FirstOtherAtom += TopOrigin->getPosition(); 519 *SecondOtherAtom += TopOrigin->getPosition(); 520 *ThirdOtherAtom += TopOrigin->getPosition(); 523 521 524 522 // ... and add to molecule … … 596 594 *item >> x[1]; 597 595 *item >> x[2]; 598 Walker-> type = elemente->FindElement(shorthand);599 if (Walker-> type== NULL) {596 Walker->setType(elemente->FindElement(shorthand)); 597 if (Walker->getType() == NULL) { 600 598 DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H."); 601 Walker-> type = elemente->FindElement(1);599 Walker->setType(1); 602 600 } 603 601 if (Walker->Trajectory.R.size() <= (unsigned int)MDSteps) { … … 606 604 Walker->Trajectory.F.resize(MDSteps+10); 607 605 } 606 Walker->setPosition(Vector(x)); 608 607 for(j=NDIM;j--;) { 609 Walker->x[j] = x[j];610 608 Walker->Trajectory.R.at(MDSteps-1)[j] = x[j]; 611 609 Walker->Trajectory.U.at(MDSteps-1)[j] = 0; … … 702 700 atom1->RegisterBond(Binder); 703 701 atom2->RegisterBond(Binder); 704 if ((atom1-> type != NULL) && (atom1->type->Z != 1) && (atom2->type != NULL) && (atom2->type->Z != 1))702 if ((atom1->getType() != NULL) && (atom1->getType()->Z != 1) && (atom2->getType() != NULL) && (atom2->getType()->Z != 1)) 705 703 NoNonBonds++; 706 704 … … 776 774 ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom()."); 777 775 OBSERVE; 778 formula-=pointer-> type;776 formula-=pointer->getType(); 779 777 RemoveBonds(pointer); 780 778 erase(pointer); … … 790 788 if (pointer == NULL) 791 789 return false; 792 formula-=pointer-> type;790 formula-=pointer->getType(); 793 791 erase(pointer); 794 792 return true; … … 972 970 for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { 973 971 (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 974 if ((*iter)-> type->Z != 1) // count non-hydrogen atoms whilst at it972 if ((*iter)->getType()->Z != 1) // count non-hydrogen atoms whilst at it 975 973 NoNonHydrogen++; 976 974 stringstream sstr; 977 sstr << (*iter)-> type->getSymbol() << (*iter)->nr+1;975 sstr << (*iter)->getType()->getSymbol() << (*iter)->nr+1; 978 976 (*iter)->setName(sstr.str()); 979 977 DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->getName() << "." << endl);
Note:
See TracChangeset
for help on using the changeset viewer.