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*, std::size_t);
135 void init(
const MolecularGraph*,
const Bond*, LGNode*, LGNode*, std::size_t);
137 const Atom* getSpiroCenter()
const;
138 const Bond* getBond()
const;
140 LGNode* otherNode(
const LGNode*)
const;
143 std::size_t getID()
const;
145 bool hasConfigConstraint()
const;
149 bool initConfigInfo();
151 const MolecularGraph* molGraph;
152 const Atom* spiroCenter;
158 unsigned int configuration;
159 const Atom* configRefAtoms[2];
163 typedef std::vector<std::size_t> AtomIndexList;
164 typedef std::vector<const Bond*> BondList;
165 typedef std::vector<LGNode*> NodeList;
188 void init(
const MolecularGraph* molgraph);
190 virtual void addEdge(
const Atom*,
const LGEdge*) = 0;
192 virtual void getChildNodes(NodeList&)
const = 0;
194 virtual void init() = 0;
196 virtual void createChildLayouts() = 0;
198 virtual double getPriority()
const = 0;
202 virtual void layout() = 0;
203 virtual bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool) = 0;
205 virtual bool layoutChildNodes(std::size_t&, std::size_t,
bool) = 0;
207 virtual Type
getType()
const = 0;
209 virtual double getAngularDemand(
const Atom*)
const;
211 virtual bool setParentEdge(
const LGEdge*, Direction) = 0;
214 std::size_t countAtomCollisions(
const AtomIndexList&,
const AtomIndexList&,
const Math::Vector2DArray&);
215 std::size_t countAtomCollisionsForAtom(std::size_t,
const AtomIndexList&,
const Math::Vector2DArray&);
217 std::size_t countBondCollisions(
const BondList&,
const BondList&,
const Math::Vector2DArray&);
218 std::size_t countBondCollisionsForBond(
const Bond*,
const BondList&,
const Math::Vector2DArray&);
220 std::size_t countAtomBondCollisions(
const AtomIndexList&,
const BondList&,
const Math::Vector2DArray&);
221 std::size_t countBondCollisionsForAtom(std::size_t,
const BondList&,
const Math::Vector2DArray&);
223 std::size_t countBondAtomCollisions(
const BondList&,
const AtomIndexList&,
const Math::Vector2DArray&);
224 std::size_t countAtomCollisionsForBond(
const Bond*,
const AtomIndexList&,
const Math::Vector2DArray&);
232 edge(edge), angle(angle) {}
238 typedef std::vector<NodeLayoutInfo> NodeLayoutInfoList;
239 typedef std::pair<double, double> AngleRange;
241 class EdgePriorityGreaterCmpFunc;
243 class LinkedNodePriorityLessCmpFunc;
244 class LinkedNodePriorityEqualCmpFunc;
246 class NodeLayoutInfoListEqualCmpFunc;
251 typedef std::list<RingInfo*> RingInfoList;
252 typedef std::vector<const LGEdge*> EdgeList;
254 class RingSysNode :
public LGNode
261 AtomIndexList&, BondList&);
266 bool containsAtom(std::size_t)
const;
268 bool addRing(
const RingInfo*);
270 void addEdge(
const Atom*,
const LGEdge*);
272 void getChildNodes(NodeList&)
const;
276 double getPriority()
const;
281 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
283 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
287 double getAngularDemand(
const Atom*)
const;
289 bool setParentEdge(
const LGEdge*, Direction);
292 bool layoutChildNodes(
double,
double,
bool,
double, std::size_t&, std::size_t,
bool);
293 bool layoutChildNodes(std::size_t, std::size_t&, std::size_t,
bool);
295 void createChildLayouts();
296 void createChildLayouts(
const Atom*, EdgeList&);
298 bool layout(std::size_t,
const Math::Vector2D&,
double,
bool,
double, std::size_t&, std::size_t);
300 void transformCoords(std::size_t,
const Math::Vector2D&,
double,
bool,
double);
302 double transformEdgeAngle(
double)
const;
306 void commitAtomAndBondList()
const;
310 void calcCoordsForRing(
const RingInfo*);
311 void calcCoordsForRingSegment(
const RingInfo*);
315 void initSpringLayoutParams();
316 void performSpringLayout();
318 void performDistGeomLayout();
319 bool needDistGeomLayout()
const;
320 bool addBondStereoDGConstraints(
const RingInfo* ring_info);
321 void addBondAngleDGConstraints(
const RingInfo* ring_info);
322 void addDefaultDGConstraints();
324 const Chem::Atom* getExoBondAtom(
const RingInfo* ring_info,
const Atom& atom, std::size_t rings_nbrs[2])
const;
327 Math::Vector2D computePartialDerivative(std::size_t, std::size_t)
const;
329 bool layoutFinished(
bool,
double,
double&,
double&)
const;
331 void distributeWeightFactors(std::size_t,
double,
const Math::ULMatrix&);
333 void calcFreeSweeps();
335 bool getNextRingSegment(
const RingInfo*);
341 typedef std::pair<std::size_t, std::size_t> DistConstraintKey;
342 typedef boost::unordered_set<DistConstraintKey> DistConstraintKeySet;
343 typedef std::vector<const RingInfo*> RingInfoList;
344 typedef std::list<const RingInfo*> RingLayoutQueue;
345 typedef std::map<std::size_t, EdgeList> EdgeListMap;
346 typedef std::map<const Atom*, AngleRange> AngleRangeMap;
347 typedef std::deque<std::size_t> RingSegment;
348 typedef std::vector<std::vector<NodeLayoutInfoList> > NodeLayoutInfoListTable;
349 typedef std::vector<std::size_t> LayoutIndexTable;
350 typedef std::vector<const Atom*> AtomTable;
351 typedef std::vector<Math::Vector2D> EnergyDerivativeTable;
352 typedef std::vector<double> WeightFactorTable;
359 RingInfoList ringList;
360 RingLayoutQueue ringLayoutQueue;
361 RingSegment ringSegment;
362 EdgeListMap edgeListMap;
363 AngleRangeMap freeSweepMap;
364 AtomIndexList atomList;
366 AtomIndexList* procAtomList;
367 BondList* procBondList;
370 const LGEdge* parentEdge;
371 const Atom* parentEdgeAtom;
372 EdgeList parentEdgeAtomEdges;
373 NodeLayoutInfoListTable childLayouts;
374 LayoutIndexTable childLayoutIndexTable;
375 AtomTable edgeAtomTable;
377 std::size_t rsysLayoutIndex;
378 double parentEdgeAngle;
380 double rsysAxisAngle;
382 WeightFactorTable layoutWeightFactors;
383 EnergyDerivativeTable layoutEnergyDerivatives;
386 DGCoordsGenerator dgCoordsGenerator;
387 DistConstraintKeySet setDistConstraints;
390 class AtomNode :
public LGNode
396 void addEdge(
const Atom*,
const LGEdge*);
398 const Atom* getAtom()
const;
399 std::size_t getAtomIndex()
const;
401 void getChildNodes(NodeList&)
const;
405 double getPriority()
const;
412 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
414 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
418 bool setParentEdge(
const LGEdge*, Direction);
421 struct LayoutParameters
424 LayoutParameters(std::size_t num_colls):
425 numCollisions(num_colls) {}
427 std::size_t numCollisions;
428 double bondLength{0.0};
429 double edgeAngle{0.0};
432 void layout(
double,
double,
const Math::Vector2D&, std::size_t, std::size_t, LayoutParameters&);
434 std::size_t getChildNodeTypePattern()
const;
436 void createChildLayouts();
438 void createChildLayoutsD1();
439 void createChildLayoutsD2();
440 void createChildLayoutsD3();
441 void createChildLayoutsD4();
442 void createChildLayoutsDN();
444 void removeChildLayoutSymmetryDuplicates();
446 void removeParentEdge();
448 void sortChildEdges();
450 typedef std::vector<NodeLayoutInfoList> NodeLayoutInfoListTable;
453 std::size_t atomIndex;
458 AtomIndexList* procAtomList;
459 BondList* procBondList;
461 Direction chainDirection;
462 double parentEdgeAngle;
464 const LGEdge* parentEdge;
465 NodeLayoutInfoListTable childLayouts;
466 std::size_t childLayoutIndex;
467 Direction childChainDirections[4];
470 typedef std::pair<Math::Vector2D, Math::Vector2D> BoundingBox;
474 void extractRingInformation();
476 void calcAtomPriorities();
477 void calcRingPriorities();
484 void moveComponent(
const BoundingBox&,
double,
double,
const Fragment&,
Math::Vector2DArray&);
491 void createBondEdges(
const Fragment&);
492 void createSpiroEdges(
const Fragment&);
494 void setAtomNodeChainIDs();
496 void findLongestNodePath(AtomNode*,
const AtomNode*);
498 void createBFSNodeList();
499 void initNodes()
const;
502 bool layoutChildNodes(std::size_t);
504 LGEdge* allocEdge(
const Atom*, LGNode*, LGNode*);
505 LGEdge* allocEdge(
const Bond*, LGNode*, LGNode*);
507 RingInfo* allocRingInfo(
const Fragment&);
512 void freeAllocEdges();
513 void freeAllocRingInfos();
514 void freeAllocRingSysNodes();
515 void freeAllocAtomNodes();
517 typedef std::vector<AtomNode*> AtomNodeList;
518 typedef std::vector<std::size_t> AtomPriorityTable;
519 typedef Util::ObjectStack<RingInfo> RingInfoCache;
520 typedef Util::ObjectStack<RingSysNode> RingSysNodeCache;
521 typedef Util::ObjectStack<AtomNode> AtomNodeCache;
522 typedef Util::ObjectStack<LGEdge> EdgeCache;
523 typedef std::vector<RingSysNode*> RingSysNodeList;
525 const MolecularGraph* molGraph;
526 RingInfoCache ringInfoCache;
527 RingSysNodeCache ringSysNodeCache;
528 AtomNodeCache atomNodeCache;
531 RingInfoList ringList;
532 RingSysNodeList ringSysNodeList;
533 AtomNodeList atomNodeList;
534 RingInfoList tmpRingList;
535 NodeList bfsNodeList;
536 AtomNodeList atomNodeTable;
537 AtomNodeList longestAtomNodePath;
538 AtomNodeList currAtomNodePath;
539 AtomIndexList procAtomList;
540 BondList procBondList;
544 AtomPriorityTable atomPriorityTable;
545 std::size_t numAtoms;
546 std::size_t numBonds;
547 bool strictLayoutGeometry;
548 std::size_t numLayoutCollisions;
549 std::size_t maxNumLayoutCollisions;
550 std::size_t backtrackingCount;
551 std::size_t nextEdgeID;
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:229
const LGEdge * edge
Definition: Atom2DCoordinatesCalculator.hpp:234
double angle
Definition: Atom2DCoordinatesCalculator.hpp:235
NodeLayoutInfo(const LGEdge *edge, double angle)
Definition: Atom2DCoordinatesCalculator.hpp:231