29 #ifndef CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
30 #define CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
39 #include <boost/unordered_set.hpp>
109 const Fragment& getFragment()
const;
114 double getPriority()
const;
115 void setPriority(
double);
117 std::size_t getSize()
const;
139 void init(
const MolecularGraph*,
const Atom*, LGNode*, LGNode*, std::size_t);
140 void init(
const MolecularGraph*,
const Bond*, LGNode*, LGNode*, std::size_t);
142 const Atom* getSpiroCenter()
const;
143 const Bond* getBond()
const;
145 LGNode* otherNode(
const LGNode*)
const;
148 std::size_t getID()
const;
150 bool hasConfigConstraint()
const;
154 bool initConfigInfo();
156 const MolecularGraph* molGraph;
157 const Atom* spiroCenter;
163 unsigned int configuration;
164 const Atom* configRefAtoms[2];
168 typedef std::vector<std::size_t> AtomIndexList;
169 typedef std::vector<const Bond*> BondList;
170 typedef std::vector<LGNode*> NodeList;
193 void init(
const MolecularGraph* molgraph);
195 virtual void addEdge(
const Atom*,
const LGEdge*) = 0;
197 virtual void getChildNodes(NodeList&)
const = 0;
199 virtual void init() = 0;
201 virtual void createChildLayouts() = 0;
203 virtual double getPriority()
const = 0;
207 virtual void layout() = 0;
208 virtual bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool) = 0;
210 virtual bool layoutChildNodes(std::size_t&, std::size_t,
bool) = 0;
212 virtual Type
getType()
const = 0;
214 virtual double getAngularDemand(
const Atom*)
const;
216 virtual bool setParentEdge(
const LGEdge*, Direction) = 0;
219 std::size_t countAtomCollisions(
const AtomIndexList&,
const AtomIndexList&,
const Math::Vector2DArray&);
220 std::size_t countAtomCollisionsForAtom(std::size_t,
const AtomIndexList&,
const Math::Vector2DArray&);
222 std::size_t countBondCollisions(
const BondList&,
const BondList&,
const Math::Vector2DArray&);
223 std::size_t countBondCollisionsForBond(
const Bond*,
const BondList&,
const Math::Vector2DArray&);
225 std::size_t countAtomBondCollisions(
const AtomIndexList&,
const BondList&,
const Math::Vector2DArray&);
226 std::size_t countBondCollisionsForAtom(std::size_t,
const BondList&,
const Math::Vector2DArray&);
228 std::size_t countBondAtomCollisions(
const BondList&,
const AtomIndexList&,
const Math::Vector2DArray&);
229 std::size_t countAtomCollisionsForBond(
const Bond*,
const AtomIndexList&,
const Math::Vector2DArray&);
237 edge(edge), angle(angle) {}
243 typedef std::vector<NodeLayoutInfo> NodeLayoutInfoList;
244 typedef std::pair<double, double> AngleRange;
246 class EdgePriorityGreaterCmpFunc;
248 class LinkedNodePriorityLessCmpFunc;
249 class LinkedNodePriorityEqualCmpFunc;
251 class NodeLayoutInfoListEqualCmpFunc;
256 typedef std::list<RingInfo*> RingInfoList;
257 typedef std::vector<const LGEdge*> EdgeList;
259 class RingSysNode :
public LGNode
266 AtomIndexList&, BondList&);
271 bool containsAtom(std::size_t)
const;
273 bool addRing(
const RingInfo*);
275 void addEdge(
const Atom*,
const LGEdge*);
277 void getChildNodes(NodeList&)
const;
281 double getPriority()
const;
286 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
288 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
292 double getAngularDemand(
const Atom*)
const;
294 bool setParentEdge(
const LGEdge*, Direction);
297 bool layoutChildNodes(
double,
double,
bool,
double, std::size_t&, std::size_t,
bool);
298 bool layoutChildNodes(std::size_t, std::size_t&, std::size_t,
bool);
300 void createChildLayouts();
301 void createChildLayouts(
const Atom*, EdgeList&);
303 bool layout(std::size_t,
const Math::Vector2D&,
double,
bool,
double, std::size_t&, std::size_t);
305 void transformCoords(std::size_t,
const Math::Vector2D&,
double,
bool,
double);
307 double transformEdgeAngle(
double)
const;
311 void commitAtomAndBondList()
const;
315 void calcCoordsForRing(
const RingInfo*);
316 void calcCoordsForRingSegment(
const RingInfo*);
320 void initSpringLayoutParams();
321 void performSpringLayout();
323 void performDistGeomLayout();
324 bool needDistGeomLayout()
const;
325 bool addBondStereoDGConstraints(
const RingInfo* ring_info);
326 void addBondAngleDGConstraints(
const RingInfo* ring_info);
327 void addDefaultDGConstraints();
329 const Chem::Atom* getExoBondAtom(
const RingInfo* ring_info,
const Atom& atom, std::size_t rings_nbrs[2])
const;
332 Math::Vector2D computePartialDerivative(std::size_t, std::size_t)
const;
334 bool layoutFinished(
bool,
double,
double&,
double&)
const;
336 void distributeWeightFactors(std::size_t,
double,
const Math::ULMatrix&);
338 void calcFreeSweeps();
340 bool getNextRingSegment(
const RingInfo*);
346 typedef std::pair<std::size_t, std::size_t> DistConstraintKey;
347 typedef boost::unordered_set<DistConstraintKey> DistConstraintKeySet;
348 typedef std::vector<const RingInfo*> RingInfoList;
349 typedef std::list<const RingInfo*> RingLayoutQueue;
350 typedef std::map<std::size_t, EdgeList> EdgeListMap;
351 typedef std::map<const Atom*, AngleRange> AngleRangeMap;
352 typedef std::deque<std::size_t> RingSegment;
353 typedef std::vector<std::vector<NodeLayoutInfoList> > NodeLayoutInfoListTable;
354 typedef std::vector<std::size_t> LayoutIndexTable;
355 typedef std::vector<const Atom*> AtomTable;
356 typedef std::vector<Math::Vector2D> EnergyDerivativeTable;
357 typedef std::vector<double> WeightFactorTable;
364 RingInfoList ringList;
365 RingLayoutQueue ringLayoutQueue;
366 RingSegment ringSegment;
367 EdgeListMap edgeListMap;
368 AngleRangeMap freeSweepMap;
369 AtomIndexList atomList;
371 AtomIndexList* procAtomList;
372 BondList* procBondList;
375 const LGEdge* parentEdge;
376 const Atom* parentEdgeAtom;
377 EdgeList parentEdgeAtomEdges;
378 NodeLayoutInfoListTable childLayouts;
379 LayoutIndexTable childLayoutIndexTable;
380 AtomTable edgeAtomTable;
382 std::size_t rsysLayoutIndex;
383 double parentEdgeAngle;
385 double rsysAxisAngle;
387 WeightFactorTable layoutWeightFactors;
388 EnergyDerivativeTable layoutEnergyDerivatives;
391 DGCoordsGenerator dgCoordsGenerator;
392 DistConstraintKeySet setDistConstraints;
395 class AtomNode :
public LGNode
401 void addEdge(
const Atom*,
const LGEdge*);
403 const Atom* getAtom()
const;
404 std::size_t getAtomIndex()
const;
406 void getChildNodes(NodeList&)
const;
410 double getPriority()
const;
417 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
419 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
423 bool setParentEdge(
const LGEdge*, Direction);
426 struct LayoutParameters
429 LayoutParameters(std::size_t num_colls):
430 numCollisions(num_colls) {}
432 std::size_t numCollisions;
433 double bondLength{0.0};
434 double edgeAngle{0.0};
437 void layout(
double,
double,
const Math::Vector2D&, std::size_t, std::size_t, LayoutParameters&);
439 std::size_t getChildNodeTypePattern()
const;
441 void createChildLayouts();
443 void createChildLayoutsD1();
444 void createChildLayoutsD2();
445 void createChildLayoutsD3();
446 void createChildLayoutsD4();
447 void createChildLayoutsDN();
449 void removeChildLayoutSymmetryDuplicates();
451 void removeParentEdge();
453 void sortChildEdges();
455 typedef std::vector<NodeLayoutInfoList> NodeLayoutInfoListTable;
458 std::size_t atomIndex;
463 AtomIndexList* procAtomList;
464 BondList* procBondList;
466 Direction chainDirection;
467 double parentEdgeAngle;
469 const LGEdge* parentEdge;
470 NodeLayoutInfoListTable childLayouts;
471 std::size_t childLayoutIndex;
472 Direction childChainDirections[4];
475 typedef std::pair<Math::Vector2D, Math::Vector2D> BoundingBox;
479 void extractRingInformation();
481 void calcAtomPriorities();
482 void calcRingPriorities();
489 void moveComponent(
const BoundingBox&,
double,
double,
const Fragment&,
Math::Vector2DArray&);
496 void createBondEdges(
const Fragment&);
497 void createSpiroEdges(
const Fragment&);
499 void setAtomNodeChainIDs();
501 void findLongestNodePath(AtomNode*,
const AtomNode*);
503 void createBFSNodeList();
504 void initNodes()
const;
507 bool layoutChildNodes(std::size_t);
509 LGEdge* allocEdge(
const Atom*, LGNode*, LGNode*);
510 LGEdge* allocEdge(
const Bond*, LGNode*, LGNode*);
512 RingInfo* allocRingInfo(
const Fragment&);
517 void freeAllocEdges();
518 void freeAllocRingInfos();
519 void freeAllocRingSysNodes();
520 void freeAllocAtomNodes();
522 typedef std::vector<AtomNode*> AtomNodeList;
523 typedef std::vector<std::size_t> AtomPriorityTable;
524 typedef Util::ObjectStack<RingInfo> RingInfoCache;
525 typedef Util::ObjectStack<RingSysNode> RingSysNodeCache;
526 typedef Util::ObjectStack<AtomNode> AtomNodeCache;
527 typedef Util::ObjectStack<LGEdge> EdgeCache;
528 typedef std::vector<RingSysNode*> RingSysNodeList;
530 const MolecularGraph* molGraph;
531 RingInfoCache ringInfoCache;
532 RingSysNodeCache ringSysNodeCache;
533 AtomNodeCache atomNodeCache;
536 RingInfoList ringList;
537 RingSysNodeList ringSysNodeList;
538 AtomNodeList atomNodeList;
539 RingInfoList tmpRingList;
540 NodeList bfsNodeList;
541 AtomNodeList atomNodeTable;
542 AtomNodeList longestAtomNodePath;
543 AtomNodeList currAtomNodePath;
544 AtomIndexList procAtomList;
545 BondList procBondList;
549 AtomPriorityTable atomPriorityTable;
550 std::size_t numAtoms;
551 std::size_t numBonds;
552 bool strictLayoutGeometry;
553 std::size_t numLayoutCollisions;
554 std::size_t maxNumLayoutCollisions;
555 std::size_t backtrackingCount;
556 std::size_t nextEdgeID;
Declaration of 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 class CDPL::Util::ObjectStack.
Definition of class CDPL::Math::VectorArray.
Generates 2D coordinates for the atoms of a molecular graph using a layout algorithm that combines ri...
Definition: Atom2DCoordinatesCalculator.hpp:69
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
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Concrete Chem::MolecularGraph implementation that stores references to a selectable subset of atoms a...
Definition: Fragment.hpp:57
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
CDPL_BIOMOL_API const std::string & getChainID(const Chem::Atom &atom)
Returns the value of the Biomol::AtomProperty::CHAIN_ID property of atom.
CDPL_BIOMOL_API void setChainID(Chem::Atom &atom, const std::string &id)
Sets the value of the Biomol::AtomProperty::CHAIN_ID property of atom to 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)
Returns the Chem::AtomProperty::TYPE property of atom (see namespace Chem::AtomType).
Matrix< unsigned long > ULMatrix
Unbounded dense matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3155
CVector< double, 2 > Vector2D
Bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:2932
VectorArray< Vector2D > Vector2DArray
Array storing vectors of type Math::Vector2D.
Definition: VectorArray.hpp:80
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.
Definition: Atom2DCoordinatesCalculator.hpp:234
const LGEdge * edge
Definition: Atom2DCoordinatesCalculator.hpp:239
double angle
Definition: Atom2DCoordinatesCalculator.hpp:240
NodeLayoutInfo(const LGEdge *edge, double angle)
Definition: Atom2DCoordinatesCalculator.hpp:236