29 #ifndef CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
30 #define CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
39 #include <boost/unordered_set.hpp>
104 const Fragment& getFragment()
const;
109 double getPriority()
const;
110 void setPriority(
double);
112 std::size_t getSize()
const;
134 void init(
const MolecularGraph*,
const Atom*, LGNode*, LGNode*);
135 void init(
const MolecularGraph*,
const Bond*, LGNode*, LGNode*);
137 const Atom* getSpiroCenter()
const;
138 const Bond* getBond()
const;
140 LGNode* otherNode(
const LGNode*)
const;
144 bool hasConfigConstraint()
const;
148 bool initConfigInfo();
150 const MolecularGraph* molGraph;
151 const Atom* spiroCenter;
157 unsigned int configuration;
158 const Atom* configRefAtoms[2];
161 typedef std::vector<std::size_t> AtomIndexList;
162 typedef std::vector<const Bond*> BondList;
163 typedef std::vector<LGNode*> NodeList;
186 void init(
const MolecularGraph* molgraph);
188 virtual void addEdge(
const Atom*,
const LGEdge*) = 0;
190 virtual void getChildNodes(NodeList&)
const = 0;
192 virtual void init() = 0;
194 virtual void createChildLayouts() = 0;
196 virtual double getPriority()
const = 0;
200 virtual void layout() = 0;
201 virtual bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool) = 0;
203 virtual bool layoutChildNodes(std::size_t&, std::size_t,
bool) = 0;
205 virtual Type
getType()
const = 0;
207 virtual double getAngularDemand(
const Atom*)
const;
209 virtual bool setParentEdge(
const LGEdge*, Direction) = 0;
212 std::size_t countAtomCollisions(
const AtomIndexList&,
const AtomIndexList&,
const Math::Vector2DArray&);
213 std::size_t countAtomCollisionsForAtom(std::size_t,
const AtomIndexList&,
const Math::Vector2DArray&);
215 std::size_t countBondCollisions(
const BondList&,
const BondList&,
const Math::Vector2DArray&);
216 std::size_t countBondCollisionsForBond(
const Bond*,
const BondList&,
const Math::Vector2DArray&);
218 std::size_t countAtomBondCollisions(
const AtomIndexList&,
const BondList&,
const Math::Vector2DArray&);
219 std::size_t countBondCollisionsForAtom(std::size_t,
const BondList&,
const Math::Vector2DArray&);
221 std::size_t countBondAtomCollisions(
const BondList&,
const AtomIndexList&,
const Math::Vector2DArray&);
222 std::size_t countAtomCollisionsForBond(
const Bond*,
const AtomIndexList&,
const Math::Vector2DArray&);
230 edge(edge), angle(angle) {}
236 typedef std::vector<NodeLayoutInfo> NodeLayoutInfoList;
237 typedef std::pair<double, double> AngleRange;
239 class EdgePriorityGreaterCmpFunc;
241 class LinkedNodePriorityLessCmpFunc;
242 class LinkedNodePriorityEqualCmpFunc;
244 class NodeLayoutInfoListEqualCmpFunc;
249 typedef std::list<RingInfo*> RingInfoList;
250 typedef std::vector<const LGEdge*> EdgeList;
252 class RingSysNode :
public LGNode
259 AtomIndexList&, BondList&);
264 bool containsAtom(std::size_t)
const;
266 bool addRing(
const RingInfo*);
268 void addEdge(
const Atom*,
const LGEdge*);
270 void getChildNodes(NodeList&)
const;
274 double getPriority()
const;
279 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
281 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
285 double getAngularDemand(
const Atom*)
const;
287 bool setParentEdge(
const LGEdge*, Direction);
290 bool layoutChildNodes(
double,
double,
bool,
double, std::size_t&, std::size_t,
bool);
291 bool layoutChildNodes(std::size_t, std::size_t&, std::size_t,
bool);
293 void createChildLayouts();
294 void createChildLayouts(
const Atom*, EdgeList&);
296 bool layout(std::size_t,
const Math::Vector2D&,
double,
bool,
double, std::size_t&, std::size_t);
298 void transformCoords(std::size_t,
const Math::Vector2D&,
double,
bool,
double);
300 double transformEdgeAngle(
double)
const;
304 void commitAtomAndBondList()
const;
308 void calcCoordsForRing(
const RingInfo*);
309 void calcCoordsForRingSegment(
const RingInfo*);
313 void initSpringLayoutParams();
314 void performSpringLayout();
316 void performDistGeomLayout();
317 bool needDistGeomLayout()
const;
318 bool addBondStereoDGConstraints(
const RingInfo* ring_info);
319 void addBondAngleDGConstraints(
const RingInfo* ring_info);
320 void addDefaultDGConstraints();
322 const Chem::Atom* getExoBondAtom(
const RingInfo* ring_info,
const Atom& atom, std::size_t rings_nbrs[2])
const;
325 Math::Vector2D computePartialDerivative(std::size_t, std::size_t)
const;
327 bool layoutFinished(
bool,
double,
double&,
double&)
const;
329 void distributeWeightFactors(std::size_t,
double,
const Math::ULMatrix&);
331 void calcFreeSweeps();
333 bool getNextRingSegment(
const RingInfo*);
339 typedef std::pair<std::size_t, std::size_t> DistConstraintKey;
340 typedef boost::unordered_set<DistConstraintKey> DistConstraintKeySet;
341 typedef std::vector<const RingInfo*> RingInfoList;
342 typedef std::list<const RingInfo*> RingLayoutQueue;
343 typedef std::map<const Atom*, EdgeList> EdgeListMap;
344 typedef std::map<const Atom*, AngleRange> AngleRangeMap;
345 typedef std::deque<std::size_t> RingSegment;
346 typedef std::vector<std::vector<NodeLayoutInfoList> > NodeLayoutInfoListTable;
347 typedef std::vector<std::size_t> LayoutIndexTable;
348 typedef std::vector<const Atom*> AtomTable;
349 typedef std::vector<Math::Vector2D> EnergyDerivativeTable;
350 typedef std::vector<double> WeightFactorTable;
357 RingInfoList ringList;
358 RingLayoutQueue ringLayoutQueue;
359 RingSegment ringSegment;
360 EdgeListMap edgeListMap;
361 AngleRangeMap freeSweepMap;
362 AtomIndexList atomList;
364 AtomIndexList* procAtomList;
365 BondList* procBondList;
368 const LGEdge* parentEdge;
369 const Atom* parentEdgeAtom;
370 EdgeList parentEdgeAtomEdges;
371 NodeLayoutInfoListTable childLayouts;
372 LayoutIndexTable childLayoutIndexTable;
373 AtomTable edgeAtomTable;
375 std::size_t rsysLayoutIndex;
376 double parentEdgeAngle;
378 double rsysAxisAngle;
380 WeightFactorTable layoutWeightFactors;
381 EnergyDerivativeTable layoutEnergyDerivatives;
384 DGCoordsGenerator dgCoordsGenerator;
385 DistConstraintKeySet setDistConstraints;
388 class AtomNode :
public LGNode
394 void addEdge(
const Atom*,
const LGEdge*);
396 const Atom* getAtom()
const;
397 std::size_t getAtomIndex()
const;
399 void getChildNodes(NodeList&)
const;
403 double getPriority()
const;
410 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
412 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
416 bool setParentEdge(
const LGEdge*, Direction);
419 struct LayoutParameters
422 LayoutParameters(std::size_t num_colls):
423 numCollisions(num_colls) {}
425 std::size_t numCollisions;
430 void layout(
double,
double,
const Math::Vector2D&, std::size_t, std::size_t, LayoutParameters&);
432 std::size_t getChildNodeTypePattern()
const;
434 void createChildLayouts();
436 void createChildLayoutsD1();
437 void createChildLayoutsD2();
438 void createChildLayoutsD3();
439 void createChildLayoutsD4();
440 void createChildLayoutsDN();
442 void removeChildLayoutSymmetryDuplicates();
444 void removeParentEdge();
446 void sortChildEdges();
448 typedef std::vector<NodeLayoutInfoList> NodeLayoutInfoListTable;
451 std::size_t atomIndex;
456 AtomIndexList* procAtomList;
457 BondList* procBondList;
459 Direction chainDirection;
460 double parentEdgeAngle;
462 const LGEdge* parentEdge;
463 NodeLayoutInfoListTable childLayouts;
464 std::size_t childLayoutIndex;
465 Direction childChainDirections[4];
468 typedef std::pair<Math::Vector2D, Math::Vector2D> BoundingBox;
472 void extractRingInformation();
474 void calcAtomPriorities();
475 void calcRingPriorities();
482 void moveComponent(
const BoundingBox&,
double,
double,
const Fragment&,
Math::Vector2DArray&);
489 void createBondEdges(
const Fragment&);
490 void createSpiroEdges(
const Fragment&);
492 void setAtomNodeChainIDs();
494 void findLongestNodePath(AtomNode*,
const AtomNode*);
496 void createBFSNodeList();
497 void initNodes()
const;
500 bool layoutChildNodes(std::size_t);
502 LGEdge* allocEdge(
const Atom*, LGNode*, LGNode*);
503 LGEdge* allocEdge(
const Bond*, LGNode*, LGNode*);
505 RingInfo* allocRingInfo(
const Fragment&);
510 void freeAllocEdges();
511 void freeAllocRingInfos();
512 void freeAllocRingSysNodes();
513 void freeAllocAtomNodes();
515 typedef std::vector<AtomNode*> AtomNodeList;
516 typedef std::vector<std::size_t> AtomPriorityTable;
517 typedef Util::ObjectStack<RingInfo> RingInfoCache;
518 typedef Util::ObjectStack<RingSysNode> RingSysNodeCache;
519 typedef Util::ObjectStack<AtomNode> AtomNodeCache;
520 typedef Util::ObjectStack<LGEdge> EdgeCache;
521 typedef std::vector<RingSysNode*> RingSysNodeList;
523 const MolecularGraph* molGraph;
524 RingInfoCache ringInfoCache;
525 RingSysNodeCache ringSysNodeCache;
526 AtomNodeCache atomNodeCache;
529 RingInfoList ringList;
530 RingSysNodeList ringSysNodeList;
531 AtomNodeList atomNodeList;
532 RingInfoList tmpRingList;
533 NodeList bfsNodeList;
534 AtomNodeList atomNodeTable;
535 AtomNodeList longestAtomNodePath;
536 AtomNodeList currAtomNodePath;
537 AtomIndexList procAtomList;
538 BondList procBondList;
542 AtomPriorityTable atomPriorityTable;
543 std::size_t numAtoms;
544 std::size_t numBonds;
545 bool strictLayoutGeometry;
546 std::size_t numLayoutCollisions;
547 std::size_t maxNumLayoutCollisions;
548 std::size_t backtrackingCount;
Definition of the type CDPL::Util::BitSet.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Implementation of a distance geometry based coordinates generator.
Definition of matrix data types.
Definition of the class CDPL::Util::ObjectStack.
Definition of the class CDPL::Math::VectorArray.
Atom2DCoordinatesCalculator.
Definition: Atom2DCoordinatesCalculator.hpp:64
Atom2DCoordinatesCalculator(const MolecularGraph &molgraph, Math::Vector2DArray &coords)
Constructs the Atom2DCoordinatesCalculator instance and calculates 2D-coordinates for the atoms of th...
Atom2DCoordinatesCalculator()
Constructs the Atom2DCoordinatesCalculator instance.
Atom2DCoordinatesCalculator & operator=(const Atom2DCoordinatesCalculator &)=delete
void calculate(const MolecularGraph &molgraph, Math::Vector2DArray &coords)
Calculates 2D-coordinates for the atoms of the molecular graph molgraph.
Atom2DCoordinatesCalculator(const Atom2DCoordinatesCalculator &)=delete
Atom.
Definition: Atom.hpp:52
Fragment.
Definition: Fragment.hpp:52
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL_BIOMOL_API const std::string & getChainID(const Chem::Atom &atom)
CDPL_BIOMOL_API void setChainID(Chem::Atom &atom, const std::string &id)
constexpr unsigned int DOWN
Specifies that the bond is directed downwards.
Definition: BondDirection.hpp:67
constexpr unsigned int UP
Specifies that the bond is directed upwards.
Definition: BondDirection.hpp:60
CDPL_CHEM_API unsigned int getType(const Atom &atom)
Matrix< unsigned long > ULMatrix
An unbounded dense matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:1824
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
VectorArray< Vector2D > Vector2DArray
An array of Math::Vector2D objects.
Definition: VectorArray.hpp:79
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.
Definition: Atom2DCoordinatesCalculator.hpp:227
const LGEdge * edge
Definition: Atom2DCoordinatesCalculator.hpp:232
double angle
Definition: Atom2DCoordinatesCalculator.hpp:233
NodeLayoutInfo(const LGEdge *edge, double angle)
Definition: Atom2DCoordinatesCalculator.hpp:229