source: src/Fragmentation/Exporters/SaturatedFragment.cpp@ ff72fb

Last change on this file since ff72fb was e6ca85, checked in by Frederik Heber <heber@…>, 11 years ago

recurseMatching() now takes connections into account.

  • matchSphericalPointDistribution() replaced by getRemainingPoints() as that describes what it does. match...() sounds symmetrical which the function is no longer as connection is associated with former _newpolygon.
  • SphericalPointDistribution now has internal points and adjacency, initialized by initSelf().
  • findBestMatching() and getRemainingPoints() are no longer static functions.
  • all unit tests are working again, including the .._multiple() that tests for joint points due to bond degree greater than 1.
  • the huge case switch in SaturatedFragment::saturateAtom() now resides in initSelf().
  • Property mode set to 100644
File size: 22.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * SaturatedFragment.cpp
26 *
27 * Created on: Mar 3, 2013
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "CodePatterns/MemDebug.hpp"
37
38#include "SaturatedFragment.hpp"
39
40#include <algorithm>
41#include <cmath>
42#include <iostream>
43
44#include "CodePatterns/Assert.hpp"
45#include "CodePatterns/Log.hpp"
46
47#include "LinearAlgebra/Exceptions.hpp"
48#include "LinearAlgebra/Plane.hpp"
49#include "LinearAlgebra/RealSpaceMatrix.hpp"
50#include "LinearAlgebra/Vector.hpp"
51
52#include "Atom/atom.hpp"
53#include "Bond/bond.hpp"
54#include "config.hpp"
55#include "Descriptors/AtomIdDescriptor.hpp"
56#include "Fragmentation/Exporters/HydrogenPool.hpp"
57#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
58#include "Fragmentation/HydrogenSaturation_enum.hpp"
59#include "Graph/BondGraph.hpp"
60#include "World.hpp"
61
62SaturatedFragment::SaturatedFragment(
63 const KeySet &_set,
64 KeySetsInUse_t &_container,
65 HydrogenPool &_hydrogens,
66 const enum HydrogenTreatment _treatment,
67 const enum HydrogenSaturation _saturation) :
68 container(_container),
69 set(_set),
70 hydrogens(_hydrogens),
71 FullMolecule(set),
72 treatment(_treatment),
73 saturation(_saturation)
74{
75 // add to in-use container
76 ASSERT( container.find(set) == container.end(),
77 "SaturatedFragment::SaturatedFragment() - the set "
78 +toString(set)+" is already marked as in use.");
79 container.insert(set);
80
81 // prepare saturation hydrogens
82 saturate();
83}
84
85SaturatedFragment::~SaturatedFragment()
86{
87 // release all saturation hydrogens if present
88 for (KeySet::iterator iter = SaturationHydrogens.begin();
89 !SaturationHydrogens.empty();
90 iter = SaturationHydrogens.begin()) {
91 hydrogens.releaseHydrogen(*iter);
92 SaturationHydrogens.erase(iter);
93 }
94
95 // remove ourselves from in-use container
96 KeySetsInUse_t::iterator iter = container.find(set);
97 ASSERT( container.find(set) != container.end(),
98 "SaturatedFragment::SaturatedFragment() - the set "
99 +toString(set)+" is not marked as in use.");
100 container.erase(iter);
101}
102
103void SaturatedFragment::saturate()
104{
105 // so far, we just have a set of keys. Hence, convert to atom refs
106 // and gather all atoms in a vector
107 std::vector<atom *> atoms;
108 for (KeySet::const_iterator iter = FullMolecule.begin();
109 iter != FullMolecule.end();
110 ++iter) {
111 atom * const Walker = World::getInstance().getAtom(AtomById(*iter));
112 ASSERT( Walker != NULL,
113 "SaturatedFragment::OutputConfig() - id "
114 +toString(*iter)+" is unknown to World.");
115 atoms.push_back(Walker);
116 }
117 LOG(4, "DEBUG: We have gathered the following atoms: " << atoms);
118
119// bool LonelyFlag = false;
120 // go through each atom of the fragment and gather all cut bonds in list
121 typedef std::map<atom *, BondList > CutBonds_t;
122 CutBonds_t CutBonds;
123 for (std::vector<atom *>::const_iterator iter = atoms.begin();
124 iter != atoms.end();
125 ++iter) {
126 atom * const Walker = *iter;
127 // start with an empty list
128 CutBonds.insert( std::make_pair(Walker, BondList() ));
129
130 // go through all bonds
131 const BondList& ListOfBonds = Walker->getListOfBonds();
132 for (BondList::const_iterator BondRunner = ListOfBonds.begin();
133 BondRunner != ListOfBonds.end();
134 ++BondRunner) {
135 atom * const OtherWalker = (*BondRunner)->GetOtherAtom(Walker);
136 // if other atom is in key set
137 if (set.find(OtherWalker->getId()) != set.end()) {
138 LOG(4, "DEBUG: Walker " << *Walker << " is bound to " << *OtherWalker << ".");
139// if (OtherWalker->getId() > Walker->getId()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
140//// std::stringstream output;
141//// output << "ACCEPT: Adding Bond: "
142// output << Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
143//// LOG(3, output.str());
144// //NumBonds[(*iter)->getNr()]++;
145// } else {
146//// LOG(3, "REJECY: Not adding bond, labels in wrong order.");
147// }
148// LonelyFlag = false;
149 } else {
150 LOG(4, "DEBUG: Walker " << *Walker << " is bound to "
151 << *OtherWalker << ", who is not in this fragment molecule.");
152 if ((treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {
153 LOG(4, "REJECT: " << *OtherWalker << " is a hydrogen, that are excluded from the set.");
154 FullMolecule.insert(OtherWalker->getId());
155 } else {
156 LOG(3, "ACCEPT: Adding " << **BondRunner << " as a cut bond.");
157 // there is always at least an empty list
158 CutBonds[Walker].push_back(*BondRunner);
159 }
160 }
161 }
162 }
163 LOG(4, "DEBUG: We have gathered the following CutBonds: " << CutBonds);
164
165 // go through all cut bonds and replace with a hydrogen
166 if (saturation == DoSaturate) {
167 for (CutBonds_t::const_iterator atomiter = CutBonds.begin();
168 atomiter != CutBonds.end(); ++atomiter) {
169 atom * const Walker = atomiter->first;
170 LOG(4, "DEBUG: We are now saturating " << *Walker);
171
172 if (!saturateAtom(Walker, atomiter->second))
173 exit(1);
174 }
175 } else
176 LOG(3, "INFO: We are not saturating cut bonds.");
177}
178
179bool SaturatedFragment::saturateAtom(
180 atom * const _atom,
181 const BondList &_cutbonds)
182{
183 // OLD WAY: use AddHydrogenReplacementAtom() on each cut bond
184// // go through each bond and replace
185// for (BondList::const_iterator bonditer = _cutbonds.begin();
186// bonditer != _cutbonds.end(); ++bonditer) {
187// atom * const OtherWalker = (*bonditer)->GetOtherAtom(_atom);
188// if (!AddHydrogenReplacementAtom(
189// (*bonditer),
190// _atom,
191// OtherWalker,
192// World::getInstance().getConfig()->IsAngstroem == 1))
193// return false;
194// }
195
196 SphericalPointDistribution::WeightedPolygon_t Polygon;
197 {
198 // prepare a list of "uncut" bonds via set_difference. For this both lists
199 // have to be sorted.
200 typedef std::vector<bond::ptr> BondVector_t;
201 BondVector_t ListOfBonds(_atom->getListOfBonds().begin(),_atom->getListOfBonds().end());
202 std::sort(ListOfBonds.begin(), ListOfBonds.end());
203 BondVector_t CutBonds(_cutbonds.begin(), _cutbonds.end());
204 std::sort(CutBonds.begin(), CutBonds.end());
205 const BondVector_t::iterator eraseiter = std::set_difference(
206 ListOfBonds.begin(), ListOfBonds.end(),
207 CutBonds.begin(), CutBonds.end(),
208 ListOfBonds.begin());
209 ListOfBonds.erase(eraseiter, ListOfBonds.end());
210
211 // gather the nodes of the shape defined by the current set of bonded atoms
212 for (BondVector_t::const_iterator bonditer = ListOfBonds.begin();
213 bonditer != ListOfBonds.end();
214 ++bonditer) {
215 Vector DistanceVector;
216 if ((*bonditer)->leftatom == _atom)
217 DistanceVector = (*bonditer)->rightatom->getPosition() - (*bonditer)->leftatom->getPosition();
218 else
219 DistanceVector = (*bonditer)->leftatom->getPosition() - (*bonditer)->rightatom->getPosition();
220 // always use unit distances
221 DistanceVector.Normalize();
222 Polygon.push_back( std::make_pair(DistanceVector, (*bonditer)->getDegree()) );
223 }
224 LOG(3, "DEBUG: Polygon of atom " << *_atom << " to saturate is " << Polygon);
225 }
226
227 unsigned int NumberOfPoints = _atom->getElement().getNoValenceOrbitals();
228 LOG(3, "DEBUG: There are " << NumberOfPoints
229 << " places to fill in in total for this atom " << *_atom << ".");
230
231 // get perfect node distribution for the given remaining atoms with respect
232 // to valence of the atoms (for a saturated fragment, resembles number of bonds)
233 // then get the number of vacant spots
234 SphericalPointDistribution polygonizer;
235 SphericalPointDistribution::Polygon_t RemainingPoints =
236 polygonizer.getRemainingPoints(Polygon, NumberOfPoints);
237
238 LOG(3, "INFO: Points identified to fill are " << RemainingPoints);
239
240 // and place hydrogen atoms at each vacant spot in the distance given by the table
241 for(SphericalPointDistribution::Polygon_t::const_iterator iter = RemainingPoints.begin();
242 iter != RemainingPoints.end(); ++iter) {
243 // find nearest atom as father to this point
244 atom * const _father = _atom;
245 LOG(4, "DEBUG: Filling saturation hydrogen for atom " << _atom << " at " << *iter);
246 const atom& hydrogen = setHydrogenReplacement(
247 _atom,
248 *iter,
249 1.,
250 _father);
251 FullMolecule.insert(hydrogen.getId());
252 }
253
254 return true;
255}
256
257
258bool SaturatedFragment::OutputConfig(
259 std::ostream &out,
260 const ParserTypes _type) const
261{
262 // gather all atoms in a vector
263 std::vector<atom *> atoms;
264 for (KeySet::const_iterator iter = FullMolecule.begin();
265 iter != FullMolecule.end();
266 ++iter) {
267 atom * const Walker = World::getInstance().getAtom(AtomById(*iter));
268 ASSERT( Walker != NULL,
269 "SaturatedFragment::OutputConfig() - id "
270 +toString(*iter)+" is unknown to World.");
271 atoms.push_back(Walker);
272 }
273
274 // TODO: ScanForPeriodicCorrection() is missing so far!
275 // note however that this is not straight-forward for the following reasons:
276 // - we do not copy all atoms anymore, hence we are forced to shift the real
277 // atoms hither and back again
278 // - we use a long-range potential that supports periodic boundary conditions.
279 // Hence, there we would like the original configuration (split through the
280 // the periodic boundaries). Otherwise, we would have to shift (and probably
281 // interpolate) the potential with OBCs applying.
282
283 // list atoms in fragment for debugging
284 {
285 std::stringstream output;
286 output << "INFO: Contained atoms: ";
287 for (std::vector<atom *>::const_iterator iter = atoms.begin();
288 iter != atoms.end(); ++iter) {
289 output << (*iter)->getName() << " ";
290 }
291 LOG(3, output.str());
292 }
293
294 // store to stream via FragmentParser
295 const bool intermediateResult =
296 FormatParserStorage::getInstance().save(
297 out,
298 FormatParserStorage::getInstance().getSuffixFromType(_type),
299 atoms);
300
301 return intermediateResult;
302}
303
304atom * const SaturatedFragment::getHydrogenReplacement(atom * const replacement)
305{
306 atom * const _atom = hydrogens.leaseHydrogen(); // new atom
307 _atom->setAtomicVelocity(replacement->getAtomicVelocity()); // copy velocity
308 _atom->setFixedIon(replacement->getFixedIon());
309 // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
310 _atom->father = replacement;
311 SaturationHydrogens.insert(_atom->getId());
312 return _atom;
313}
314
315const atom& SaturatedFragment::setHydrogenReplacement(
316 const atom * const _OwnerAtom,
317 const Vector &_position,
318 const double _distance,
319 atom * const _father)
320{
321 atom * const _atom = hydrogens.leaseHydrogen(); // new atom
322 _atom->setPosition( _OwnerAtom->getPosition() + _distance * _position );
323 // always set as fixed ion (not moving during molecular dynamics simulation)
324 _atom->setFixedIon(true);
325 // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
326 _atom->father = _father;
327 SaturationHydrogens.insert(_atom->getId());
328 return *_atom;
329}
330
331bool SaturatedFragment::AddHydrogenReplacementAtom(
332 bond::ptr TopBond,
333 atom *Origin,
334 atom *Replacement,
335 bool IsAngstroem)
336{
337// Info info(__func__);
338 bool AllWentWell = true; // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
339 double bondlength; // bond length of the bond to be replaced/cut
340 double bondangle; // bond angle of the bond to be replaced/cut
341 double BondRescale; // rescale value for the hydrogen bond length
342 bond::ptr FirstBond;
343 bond::ptr SecondBond; // Other bonds in double bond case to determine "other" plane
344 atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
345 double b,l,d,f,g, alpha, factors[NDIM]; // hold temporary values in triple bond case for coordination determination
346 Vector Orthovector1, Orthovector2; // temporary vectors in coordination construction
347 Vector InBondvector; // vector in direction of *Bond
348 const RealSpaceMatrix &matrix = World::getInstance().getDomain().getM();
349 bond::ptr Binder;
350
351 // create vector in direction of bond
352 InBondvector = Replacement->getPosition() - Origin->getPosition();
353 bondlength = InBondvector.Norm();
354
355 // is greater than typical bond distance? Then we have to correct periodically
356 // the problem is not the H being out of the box, but InBondvector have the wrong direction
357 // due to Replacement or Origin being on the wrong side!
358 const BondGraph * const BG = World::getInstance().getBondGraph();
359 const range<double> MinMaxBondDistance(
360 BG->getMinMaxDistance(Origin,Replacement));
361 if (!MinMaxBondDistance.isInRange(bondlength)) {
362// LOG(4, "InBondvector is: " << InBondvector << ".");
363 Orthovector1.Zero();
364 for (int i=NDIM;i--;) {
365 l = Replacement->at(i) - Origin->at(i);
366 if (fabs(l) > MinMaxBondDistance.last) { // is component greater than bond distance (check against min not useful here)
367 Orthovector1[i] = (l < 0) ? -1. : +1.;
368 } // (signs are correct, was tested!)
369 }
370 Orthovector1 *= matrix;
371 InBondvector -= Orthovector1; // subtract just the additional translation
372 bondlength = InBondvector.Norm();
373// LOG(4, "INFO: Corrected InBondvector is now: " << InBondvector << ".");
374 } // periodic correction finished
375
376 InBondvector.Normalize();
377 // get typical bond length and store as scale factor for later
378 ASSERT(Origin->getType() != NULL,
379 "SaturatedFragment::AddHydrogenReplacementAtom() - element of Origin is not given.");
380 BondRescale = Origin->getType()->getHBondDistance(TopBond->getDegree()-1);
381 if (BondRescale == -1) {
382 ELOG(1, "There is no typical hydrogen bond distance in replacing bond (" << Origin->getName() << "<->" << Replacement->getName() << ") of degree " << TopBond->getDegree() << "!");
383 BondRescale = Origin->getType()->getHBondDistance(TopBond->getDegree());
384 if (BondRescale == -1) {
385 ELOG(1, "There is no typical hydrogen bond distance in replacing bond (" << Origin->getName() << "<->" << Replacement->getName() << ") of any degree!");
386 return false;
387 BondRescale = bondlength;
388 }
389 } else {
390 if (!IsAngstroem)
391 BondRescale /= (1.*AtomicLengthToAngstroem);
392 }
393
394 // discern single, double and triple bonds
395 switch(TopBond->getDegree()) {
396 case 1:
397 // check whether replacement has been an excluded hydrogen
398 if (Replacement->getType()->getAtomicNumber() == HydrogenPool::HYDROGEN) { // neither rescale nor replace if it's already hydrogen
399 FirstOtherAtom = Replacement;
400 BondRescale = bondlength;
401 } else {
402 FirstOtherAtom = getHydrogenReplacement(Replacement);
403 InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length
404 FirstOtherAtom->setPosition(Origin->getPosition() + InBondvector); // set coordination to origin and add distance vector to replacement atom
405 }
406 FullMolecule.insert(FirstOtherAtom->getId());
407// LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << ".");
408 break;
409 case 2:
410 {
411 // determine two other bonds (warning if there are more than two other) plus valence sanity check
412 const BondList& ListOfBonds = Origin->getListOfBonds();
413 for (BondList::const_iterator Runner = ListOfBonds.begin();
414 Runner != ListOfBonds.end();
415 ++Runner) {
416 if ((*Runner) != TopBond) {
417 if (FirstBond == NULL) {
418 FirstBond = (*Runner);
419 FirstOtherAtom = (*Runner)->GetOtherAtom(Origin);
420 } else if (SecondBond == NULL) {
421 SecondBond = (*Runner);
422 SecondOtherAtom = (*Runner)->GetOtherAtom(Origin);
423 } else {
424 ELOG(2, "Detected more than four bonds for atom " << Origin->getName());
425 }
426 }
427 }
428 }
429 if (SecondOtherAtom == NULL) { // then we have an atom with valence four, but only 3 bonds: one to replace and one which is TopBond (third is FirstBond)
430 SecondBond = TopBond;
431 SecondOtherAtom = Replacement;
432 }
433 if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all
434// LOG(3, "Regarding the double bond (" << Origin->Name << "<->" << Replacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << Origin->Name << " to determine orthogonal plane.");
435
436 // determine the plane of these two with the *origin
437 try {
438 Orthovector1 = Plane(Origin->getPosition(), FirstOtherAtom->getPosition(), SecondOtherAtom->getPosition()).getNormal();
439 }
440 catch(LinearDependenceException &excp){
441 LOG(0, boost::diagnostic_information(excp));
442 // TODO: figure out what to do with the Orthovector in this case
443 AllWentWell = false;
444 }
445 } else {
446 Orthovector1.GetOneNormalVector(InBondvector);
447 }
448 //LOG(3, "INFO: Orthovector1: " << Orthovector1 << ".");
449 // orthogonal vector and bond vector between origin and replacement form the new plane
450 Orthovector1.MakeNormalTo(InBondvector);
451 Orthovector1.Normalize();
452 //LOG(3, "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << ".");
453
454 // create the two Hydrogens ...
455 FirstOtherAtom = getHydrogenReplacement(Replacement);
456 SecondOtherAtom = getHydrogenReplacement(Replacement);
457 FullMolecule.insert(FirstOtherAtom->getId());
458 FullMolecule.insert(SecondOtherAtom->getId());
459 bondangle = Origin->getType()->getHBondAngle(1);
460 if (bondangle == -1) {
461 ELOG(1, "There is no typical hydrogen bond angle in replacing bond (" << Origin->getName() << "<->" << Replacement->getName() << ") of degree " << TopBond->getDegree() << "!");
462 return false;
463 bondangle = 0;
464 }
465 bondangle *= M_PI/180./2.;
466// LOG(3, "INFO: ReScaleCheck: InBondvector " << InBondvector << ", " << Orthovector1 << ".");
467// LOG(3, "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle));
468 FirstOtherAtom->Zero();
469 SecondOtherAtom->Zero();
470 for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction)
471 FirstOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle)));
472 SecondOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)));
473 }
474 FirstOtherAtom->Scale(BondRescale); // rescale by correct BondDistance
475 SecondOtherAtom->Scale(BondRescale);
476 //LOG(3, "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << ".");
477 *FirstOtherAtom += Origin->getPosition();
478 *SecondOtherAtom += Origin->getPosition();
479 // ... and add to molecule
480// LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << ".");
481// LOG(4, "INFO: Added " << *SecondOtherAtom << " at: " << SecondOtherAtom->x << ".");
482 break;
483 case 3:
484 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
485 FirstOtherAtom = getHydrogenReplacement(Replacement);
486 SecondOtherAtom = getHydrogenReplacement(Replacement);
487 ThirdOtherAtom = getHydrogenReplacement(Replacement);
488 FullMolecule.insert(FirstOtherAtom->getId());
489 FullMolecule.insert(SecondOtherAtom->getId());
490 FullMolecule.insert(ThirdOtherAtom->getId());
491
492 // we need to vectors orthonormal the InBondvector
493 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector);
494// LOG(3, "INFO: Orthovector1: " << Orthovector1 << ".");
495 try{
496 Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal();
497 }
498 catch(LinearDependenceException &excp) {
499 LOG(0, boost::diagnostic_information(excp));
500 AllWentWell = false;
501 }
502// LOG(3, "INFO: Orthovector2: " << Orthovector2 << ".")
503
504 // create correct coordination for the three atoms
505 alpha = (Origin->getType()->getHBondAngle(2))/180.*M_PI/2.; // retrieve triple bond angle from database
506 l = BondRescale; // desired bond length
507 b = 2.*l*sin(alpha); // base length of isosceles triangle
508 d = l*sqrt(cos(alpha)*cos(alpha) - sin(alpha)*sin(alpha)/3.); // length for InBondvector
509 f = b/sqrt(3.); // length for Orthvector1
510 g = b/2.; // length for Orthvector2
511// LOG(3, "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", ");
512// LOG(3, "The three Bond lengths: " << sqrt(d*d+f*f) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g));
513 factors[0] = d;
514 factors[1] = f;
515 factors[2] = 0.;
516 FirstOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
517 factors[1] = -0.5*f;
518 factors[2] = g;
519 SecondOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
520 factors[2] = -g;
521 ThirdOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
522
523 // rescale each to correct BondDistance
524// FirstOtherAtom->x.Scale(&BondRescale);
525// SecondOtherAtom->x.Scale(&BondRescale);
526// ThirdOtherAtom->x.Scale(&BondRescale);
527
528 // and relative to *origin atom
529 *FirstOtherAtom += Origin->getPosition();
530 *SecondOtherAtom += Origin->getPosition();
531 *ThirdOtherAtom += Origin->getPosition();
532
533 // ... and add to molecule
534// LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << ".");
535// LOG(4, "INFO: Added " << *SecondOtherAtom << " at: " << SecondOtherAtom->x << ".");
536// LOG(4, "INFO: Added " << *ThirdOtherAtom << " at: " << ThirdOtherAtom->x << ".");
537 break;
538 default:
539 ELOG(1, "BondDegree does not state single, double or triple bond!");
540 AllWentWell = false;
541 break;
542 }
543
544 return AllWentWell;
545};
Note: See TracBrowser for help on using the repository browser.