29 #ifndef CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
30 #define CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
39 #include <boost/unordered_set.hpp>
110 const Fragment& getFragment()
const;
115 double getPriority()
const;
116 void setPriority(
double);
118 std::size_t getSize()
const;
140 void init(
const MolecularGraph*,
const Atom*, LGNode*, LGNode*, std::size_t);
141 void init(
const MolecularGraph*,
const Bond*, LGNode*, LGNode*, std::size_t);
143 const Atom* getSpiroCenter()
const;
144 const Bond* getBond()
const;
146 LGNode* otherNode(
const LGNode*)
const;
149 std::size_t getID()
const;
151 bool hasConfigConstraint()
const;
155 bool initConfigInfo();
157 const MolecularGraph* molGraph;
158 const Atom* spiroCenter;
164 unsigned int configuration;
165 const Atom* configRefAtoms[2];
169 typedef std::vector<std::size_t> AtomIndexList;
170 typedef std::vector<const Bond*> BondList;
171 typedef std::vector<LGNode*> NodeList;
194 void init(
const MolecularGraph* molgraph);
196 virtual void addEdge(
const Atom*,
const LGEdge*) = 0;
198 virtual void getChildNodes(NodeList&)
const = 0;
200 virtual void init() = 0;
202 virtual void createChildLayouts() = 0;
204 virtual double getPriority()
const = 0;
208 virtual void layout() = 0;
209 virtual bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool) = 0;
211 virtual bool layoutChildNodes(std::size_t&, std::size_t,
bool) = 0;
213 virtual Type
getType()
const = 0;
215 virtual double getAngularDemand(
const Atom*)
const;
217 virtual bool setParentEdge(
const LGEdge*, Direction) = 0;
220 std::size_t countAtomCollisions(
const AtomIndexList&,
const AtomIndexList&,
const Math::Vector2DArray&);
221 std::size_t countAtomCollisionsForAtom(std::size_t,
const AtomIndexList&,
const Math::Vector2DArray&);
223 std::size_t countBondCollisions(
const BondList&,
const BondList&,
const Math::Vector2DArray&);
224 std::size_t countBondCollisionsForBond(
const Bond*,
const BondList&,
const Math::Vector2DArray&);
226 std::size_t countAtomBondCollisions(
const AtomIndexList&,
const BondList&,
const Math::Vector2DArray&);
227 std::size_t countBondCollisionsForAtom(std::size_t,
const BondList&,
const Math::Vector2DArray&);
229 std::size_t countBondAtomCollisions(
const BondList&,
const AtomIndexList&,
const Math::Vector2DArray&);
230 std::size_t countAtomCollisionsForBond(
const Bond*,
const AtomIndexList&,
const Math::Vector2DArray&);
238 edge(edge), angle(angle) {}
244 typedef std::vector<NodeLayoutInfo> NodeLayoutInfoList;
245 typedef std::pair<double, double> AngleRange;
247 class EdgePriorityGreaterCmpFunc;
249 class LinkedNodePriorityLessCmpFunc;
250 class LinkedNodePriorityEqualCmpFunc;
252 class NodeLayoutInfoListEqualCmpFunc;
257 typedef std::list<RingInfo*> RingInfoList;
258 typedef std::vector<const LGEdge*> EdgeList;
260 class RingSysNode :
public LGNode
267 AtomIndexList&, BondList&);
272 bool containsAtom(std::size_t)
const;
274 bool addRing(
const RingInfo*);
276 void addEdge(
const Atom*,
const LGEdge*);
278 void getChildNodes(NodeList&)
const;
282 double getPriority()
const;
287 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
289 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
293 double getAngularDemand(
const Atom*)
const;
295 bool setParentEdge(
const LGEdge*, Direction);
298 bool layoutChildNodes(
double,
double,
bool,
double, std::size_t&, std::size_t,
bool);
299 bool layoutChildNodes(std::size_t, std::size_t&, std::size_t,
bool);
301 void createChildLayouts();
302 void createChildLayouts(
const Atom*, EdgeList&);
304 bool layout(std::size_t,
const Math::Vector2D&,
double,
bool,
double, std::size_t&, std::size_t);
306 void transformCoords(std::size_t,
const Math::Vector2D&,
double,
bool,
double);
308 double transformEdgeAngle(
double)
const;
312 void commitAtomAndBondList()
const;
316 void calcCoordsForRing(
const RingInfo*);
317 void calcCoordsForRingSegment(
const RingInfo*);
321 void initSpringLayoutParams();
322 void performSpringLayout();
324 void performDistGeomLayout();
325 bool needDistGeomLayout()
const;
326 bool addBondStereoDGConstraints(
const RingInfo* ring_info);
327 void addBondAngleDGConstraints(
const RingInfo* ring_info);
328 void addDefaultDGConstraints();
330 const Chem::Atom* getExoBondAtom(
const RingInfo* ring_info,
const Atom& atom, std::size_t rings_nbrs[2])
const;
333 Math::Vector2D computePartialDerivative(std::size_t, std::size_t)
const;
335 bool layoutFinished(
bool,
double,
double&,
double&)
const;
337 void distributeWeightFactors(std::size_t,
double,
const Math::ULMatrix&);
339 void calcFreeSweeps();
341 bool getNextRingSegment(
const RingInfo*);
347 typedef std::pair<std::size_t, std::size_t> DistConstraintKey;
348 typedef boost::unordered_set<DistConstraintKey> DistConstraintKeySet;
349 typedef std::vector<const RingInfo*> RingInfoList;
350 typedef std::list<const RingInfo*> RingLayoutQueue;
351 typedef std::map<std::size_t, EdgeList> EdgeListMap;
352 typedef std::map<const Atom*, AngleRange> AngleRangeMap;
353 typedef std::deque<std::size_t> RingSegment;
354 typedef std::vector<std::vector<NodeLayoutInfoList> > NodeLayoutInfoListTable;
355 typedef std::vector<std::size_t> LayoutIndexTable;
356 typedef std::vector<const Atom*> AtomTable;
357 typedef std::vector<Math::Vector2D> EnergyDerivativeTable;
358 typedef std::vector<double> WeightFactorTable;
365 RingInfoList ringList;
366 RingLayoutQueue ringLayoutQueue;
367 RingSegment ringSegment;
368 EdgeListMap edgeListMap;
369 AngleRangeMap freeSweepMap;
370 AtomIndexList atomList;
372 AtomIndexList* procAtomList;
373 BondList* procBondList;
376 const LGEdge* parentEdge;
377 const Atom* parentEdgeAtom;
378 EdgeList parentEdgeAtomEdges;
379 NodeLayoutInfoListTable childLayouts;
380 LayoutIndexTable childLayoutIndexTable;
381 AtomTable edgeAtomTable;
383 std::size_t rsysLayoutIndex;
384 double parentEdgeAngle;
386 double rsysAxisAngle;
388 WeightFactorTable layoutWeightFactors;
389 EnergyDerivativeTable layoutEnergyDerivatives;
392 DGCoordsGenerator dgCoordsGenerator;
393 DistConstraintKeySet setDistConstraints;
396 class AtomNode :
public LGNode
402 void addEdge(
const Atom*,
const LGEdge*);
404 const Atom* getAtom()
const;
405 std::size_t getAtomIndex()
const;
407 void getChildNodes(NodeList&)
const;
411 double getPriority()
const;
418 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
420 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
424 bool setParentEdge(
const LGEdge*, Direction);
427 struct LayoutParameters
430 LayoutParameters(std::size_t num_colls):
431 numCollisions(num_colls) {}
433 std::size_t numCollisions;
434 double bondLength{0.0};
435 double edgeAngle{0.0};
438 void layout(
double,
double,
const Math::Vector2D&, std::size_t, std::size_t, LayoutParameters&);
440 std::size_t getChildNodeTypePattern()
const;
442 void createChildLayouts();
444 void createChildLayoutsD1();
445 void createChildLayoutsD2();
446 void createChildLayoutsD3();
447 void createChildLayoutsD4();
448 void createChildLayoutsDN();
450 void removeChildLayoutSymmetryDuplicates();
452 void removeParentEdge();
454 void sortChildEdges();
456 typedef std::vector<NodeLayoutInfoList> NodeLayoutInfoListTable;
459 std::size_t atomIndex;
464 AtomIndexList* procAtomList;
465 BondList* procBondList;
467 Direction chainDirection;
468 double parentEdgeAngle;
470 const LGEdge* parentEdge;
471 NodeLayoutInfoListTable childLayouts;
472 std::size_t childLayoutIndex;
473 Direction childChainDirections[4];
476 typedef std::pair<Math::Vector2D, Math::Vector2D> BoundingBox;
480 void extractRingInformation();
482 void calcAtomPriorities();
483 void calcRingPriorities();
490 void moveComponent(
const BoundingBox&,
double,
double,
const Fragment&,
Math::Vector2DArray&);
497 void createBondEdges(
const Fragment&);
498 void createSpiroEdges(
const Fragment&);
500 void setAtomNodeChainIDs();
502 void findLongestNodePath(AtomNode*,
const AtomNode*);
504 void createBFSNodeList();
505 void initNodes()
const;
508 bool layoutChildNodes(std::size_t);
510 LGEdge* allocEdge(
const Atom*, LGNode*, LGNode*);
511 LGEdge* allocEdge(
const Bond*, LGNode*, LGNode*);
513 RingInfo* allocRingInfo(
const Fragment&);
518 void freeAllocEdges();
519 void freeAllocRingInfos();
520 void freeAllocRingSysNodes();
521 void freeAllocAtomNodes();
523 typedef std::vector<AtomNode*> AtomNodeList;
524 typedef std::vector<std::size_t> AtomPriorityTable;
525 typedef Util::ObjectStack<RingInfo> RingInfoCache;
526 typedef Util::ObjectStack<RingSysNode> RingSysNodeCache;
527 typedef Util::ObjectStack<AtomNode> AtomNodeCache;
528 typedef Util::ObjectStack<LGEdge> EdgeCache;
529 typedef std::vector<RingSysNode*> RingSysNodeList;
531 const MolecularGraph* molGraph;
532 RingInfoCache ringInfoCache;
533 RingSysNodeCache ringSysNodeCache;
534 AtomNodeCache atomNodeCache;
537 RingInfoList ringList;
538 RingSysNodeList ringSysNodeList;
539 AtomNodeList atomNodeList;
540 RingInfoList tmpRingList;
541 NodeList bfsNodeList;
542 AtomNodeList atomNodeTable;
543 AtomNodeList longestAtomNodePath;
544 AtomNodeList currAtomNodePath;
545 AtomIndexList procAtomList;
546 BondList procBondList;
550 AtomPriorityTable atomPriorityTable;
551 std::size_t numAtoms;
552 std::size_t numBonds;
553 bool strictLayoutGeometry;
554 std::size_t numLayoutCollisions;
555 std::size_t maxNumLayoutCollisions;
556 std::size_t backtrackingCount;
557 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.
Definition: Atom2DCoordinatesCalculator.hpp:68
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:58
Concrete implementation of the Chem::MolecularGraph interface that stores references to selectable Ch...
Definition: Fragment.hpp:60
Abstract base class for data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
CDPL_BIOMOL_API const std::string & getChainID(const Chem::Atom &atom)
Returns the value of the Biomol::AtomProperty::CHAIN_ID property of the atom atom.
CDPL_BIOMOL_API void setChainID(Chem::Atom &atom, const std::string &id)
Sets the value of the Biomol::AtomProperty::CHAIN_ID property of the atom 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 value of the Chem::AtomProperty::TYPE property of the atom atom.
Matrix< unsigned long > ULMatrix
Unbounded dense matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3479
CVector< double, 2 > Vector2D
Bounded 2 element vector holding floating-point values of type double.
Definition: Vector.hpp:3213
VectorArray< Vector2D > Vector2DArray
Array storing vectors of type Math::Vector2D.
Definition: VectorArray.hpp:82
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.
Definition: Atom2DCoordinatesCalculator.hpp:235
const LGEdge * edge
Definition: Atom2DCoordinatesCalculator.hpp:240
double angle
Definition: Atom2DCoordinatesCalculator.hpp:241
NodeLayoutInfo(const LGEdge *edge, double angle)
Definition: Atom2DCoordinatesCalculator.hpp:237