29 #ifndef CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
30 #define CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP
102 double getPriority()
const;
103 void setPriority(
double);
105 std::size_t getSize()
const;
127 void init(
const MolecularGraph*,
const Atom*, LGNode*, LGNode*);
128 void init(
const MolecularGraph*,
const Bond*, LGNode*, LGNode*);
130 const Atom* getSpiroCenter()
const;
131 const Bond* getBond()
const;
133 LGNode* otherNode(
const LGNode*)
const;
137 bool hasConfigConstraint()
const;
141 bool initConfigInfo();
143 const MolecularGraph* molGraph;
144 const Atom* spiroCenter;
150 unsigned int configuration;
151 const Atom* configRefAtoms[2];
154 typedef std::vector<std::size_t> AtomIndexList;
155 typedef std::vector<const Bond*> BondList;
156 typedef std::vector<LGNode*> NodeList;
179 void init(
const MolecularGraph* molgraph);
181 virtual void addEdge(
const Atom*,
const LGEdge*) = 0;
183 virtual void getChildNodes(NodeList&)
const = 0;
185 virtual void init() = 0;
187 virtual void createChildLayouts() = 0;
189 virtual double getPriority()
const = 0;
193 virtual void layout() = 0;
194 virtual bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool) = 0;
196 virtual bool layoutChildNodes(std::size_t&, std::size_t,
bool) = 0;
198 virtual Type
getType()
const = 0;
200 virtual double getAngularDemand(
const Atom*)
const;
202 virtual bool setParentEdge(
const LGEdge*, Direction) = 0;
205 std::size_t countAtomCollisions(
const AtomIndexList&,
const AtomIndexList&,
const Math::Vector2DArray&);
206 std::size_t countAtomCollisionsForAtom(std::size_t,
const AtomIndexList&,
const Math::Vector2DArray&);
208 std::size_t countBondCollisions(
const BondList&,
const BondList&,
const Math::Vector2DArray&);
209 std::size_t countBondCollisionsForBond(
const Bond*,
const BondList&,
const Math::Vector2DArray&);
211 std::size_t countAtomBondCollisions(
const AtomIndexList&,
const BondList&,
const Math::Vector2DArray&);
212 std::size_t countBondCollisionsForAtom(std::size_t,
const BondList&,
const Math::Vector2DArray&);
214 std::size_t countBondAtomCollisions(
const BondList&,
const AtomIndexList&,
const Math::Vector2DArray&);
215 std::size_t countAtomCollisionsForBond(
const Bond*,
const AtomIndexList&,
const Math::Vector2DArray&);
223 edge(edge), angle(angle) {}
229 typedef std::vector<NodeLayoutInfo> NodeLayoutInfoList;
230 typedef std::pair<double, double> AngleRange;
232 class EdgePriorityGreaterCmpFunc;
234 class LinkedNodePriorityLessCmpFunc;
235 class LinkedNodePriorityEqualCmpFunc;
237 class NodeLayoutInfoListEqualCmpFunc;
242 typedef std::list<RingInfo*> RingInfoList;
243 typedef std::vector<const LGEdge*> EdgeList;
245 class RingSysNode :
public LGNode
250 AtomIndexList&, BondList&);
255 bool containsAtom(std::size_t)
const;
257 bool addRing(
const RingInfo*);
259 void addEdge(
const Atom*,
const LGEdge*);
261 void getChildNodes(NodeList&)
const;
265 double getPriority()
const;
270 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
272 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
276 double getAngularDemand(
const Atom*)
const;
278 bool setParentEdge(
const LGEdge*, Direction);
281 bool layoutChildNodes(
double,
double,
bool,
double, std::size_t&, std::size_t,
bool);
282 bool layoutChildNodes(std::size_t, std::size_t&, std::size_t,
bool);
284 void createChildLayouts();
285 void createChildLayouts(
const Atom*, EdgeList&);
287 bool layout(std::size_t,
const Math::Vector2D&,
double,
bool,
double, std::size_t&, std::size_t);
289 void transformCoords(std::size_t,
const Math::Vector2D&,
double,
bool,
double);
291 double transformEdgeAngle(
double)
const;
295 void commitAtomAndBondList()
const;
299 void calcCoordsForRing(
const RingInfo*);
300 void calcCoordsForRingSegment(
const RingInfo*);
304 void initSpringLayoutParams();
305 void performSpringLayout();
308 Math::Vector2D computePartialDerivative(std::size_t, std::size_t)
const;
310 bool layoutFinished(
bool,
double,
double&,
double&)
const;
312 void distributeWeightFactors(std::size_t,
double,
const Math::ULMatrix&);
314 void calcFreeSweeps();
316 bool getNextRingSegment(
const RingInfo*);
321 typedef std::vector<const RingInfo*> RingInfoList;
322 typedef std::list<const RingInfo*> RingLayoutQueue;
323 typedef std::map<const Atom*, EdgeList> EdgeListMap;
324 typedef std::map<const Atom*, AngleRange> AngleRangeMap;
325 typedef std::deque<std::size_t> RingSegment;
326 typedef std::vector<std::vector<NodeLayoutInfoList> > NodeLayoutInfoListTable;
327 typedef std::vector<std::size_t> LayoutIndexTable;
328 typedef std::vector<const Atom*> AtomTable;
329 typedef std::vector<Math::Vector2D> EnergyDerivativeTable;
330 typedef std::vector<double> WeightFactorTable;
337 RingInfoList ringList;
338 RingLayoutQueue ringLayoutQueue;
339 RingSegment ringSegment;
340 EdgeListMap edgeListMap;
341 AngleRangeMap freeSweepMap;
342 AtomIndexList atomList;
344 AtomIndexList* procAtomList;
345 BondList* procBondList;
348 const LGEdge* parentEdge;
349 const Atom* parentEdgeAtom;
350 EdgeList parentEdgeAtomEdges;
351 NodeLayoutInfoListTable childLayouts;
352 LayoutIndexTable childLayoutIndexTable;
353 AtomTable edgeAtomTable;
355 std::size_t rsysLayoutIndex;
356 double parentEdgeAngle;
358 double rsysAxisAngle;
360 WeightFactorTable layoutWeightFactors;
361 EnergyDerivativeTable layoutEnergyDerivatives;
366 class AtomNode :
public LGNode
372 void addEdge(
const Atom*,
const LGEdge*);
374 const Atom* getAtom()
const;
375 std::size_t getAtomIndex()
const;
377 void getChildNodes(NodeList&)
const;
381 double getPriority()
const;
388 bool layout(
double,
const Math::Vector2D&, std::size_t&, std::size_t,
bool);
390 bool layoutChildNodes(std::size_t&, std::size_t,
bool);
394 bool setParentEdge(
const LGEdge*, Direction);
397 struct LayoutParameters
400 LayoutParameters(std::size_t num_colls):
401 numCollisions(num_colls) {}
403 std::size_t numCollisions;
408 void layout(
double,
double,
const Math::Vector2D&, std::size_t, std::size_t, LayoutParameters&);
410 std::size_t getChildNodeTypePattern()
const;
412 void createChildLayouts();
414 void createChildLayoutsD1();
415 void createChildLayoutsD2();
416 void createChildLayoutsD3();
417 void createChildLayoutsD4();
418 void createChildLayoutsDN();
420 void removeChildLayoutSymmetryDuplicates();
422 void removeParentEdge();
424 void sortChildEdges();
426 typedef std::vector<NodeLayoutInfoList> NodeLayoutInfoListTable;
429 std::size_t atomIndex;
434 AtomIndexList* procAtomList;
435 BondList* procBondList;
437 Direction chainDirection;
438 double parentEdgeAngle;
440 const LGEdge* parentEdge;
441 NodeLayoutInfoListTable childLayouts;
442 std::size_t childLayoutIndex;
443 Direction childChainDirections[4];
446 typedef std::pair<Math::Vector2D, Math::Vector2D> BoundingBox;
448 Atom2DCoordinatesCalculator(
const Atom2DCoordinatesCalculator&);
450 Atom2DCoordinatesCalculator& operator=(
const Atom2DCoordinatesCalculator&);
454 void extractRingInformation();
456 void calcAtomPriorities();
457 void calcRingPriorities();
464 void moveComponent(
const BoundingBox&,
double,
double,
const Fragment&,
Math::Vector2DArray&);
471 void createBondEdges(
const Fragment&);
472 void createSpiroEdges(
const Fragment&);
474 void setAtomNodeChainIDs();
476 void findLongestNodePath(AtomNode*,
const AtomNode*);
478 void createBFSNodeList();
479 void initNodes()
const;
482 bool layoutChildNodes(std::size_t);
484 LGEdge* allocEdge(
const Atom*, LGNode*, LGNode*);
485 LGEdge* allocEdge(
const Bond*, LGNode*, LGNode*);
487 RingInfo* allocRingInfo(
const Fragment&);
492 void freeAllocEdges();
493 void freeAllocRingInfos();
494 void freeAllocRingSysNodes();
495 void freeAllocAtomNodes();
497 typedef std::vector<AtomNode*> AtomNodeList;
498 typedef std::vector<std::size_t> AtomPriorityTable;
499 typedef Util::ObjectStack<RingInfo> RingInfoCache;
500 typedef Util::ObjectStack<RingSysNode> RingSysNodeCache;
501 typedef Util::ObjectStack<AtomNode> AtomNodeCache;
502 typedef Util::ObjectStack<LGEdge> EdgeCache;
503 typedef std::vector<RingSysNode*> RingSysNodeList;
505 const MolecularGraph* molGraph;
506 RingInfoCache ringInfoCache;
507 RingSysNodeCache ringSysNodeCache;
508 AtomNodeCache atomNodeCache;
511 RingInfoList ringList;
512 RingSysNodeList ringSysNodeList;
513 AtomNodeList atomNodeList;
514 RingInfoList tmpRingList;
515 NodeList bfsNodeList;
516 AtomNodeList atomNodeTable;
517 AtomNodeList longestAtomNodePath;
518 AtomNodeList currAtomNodePath;
519 AtomIndexList procAtomList;
520 BondList procBondList;
524 AtomPriorityTable atomPriorityTable;
525 std::size_t numAtoms;
526 std::size_t numBonds;
527 bool strictLayoutGeometry;
528 std::size_t numLayoutCollisions;
529 std::size_t maxNumLayoutCollisions;
530 std::size_t backtrackingCount;
535 #endif // CDPL_CHEM_ATOM2DCOORDINATESCALCULATOR_HPP