$darkmode
DENOPTIM
RingClosingUtils.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.utils;
20
21
22import java.util.ArrayList;
23import java.util.List;
24
25import org.openscience.cdk.interfaces.IAtom;
26import org.openscience.cdk.interfaces.IAtomContainer;
27
28import denoptim.graph.Ring;
29import denoptim.graph.Vertex;
30import denoptim.graph.rings.RingClosingAttractor;
31
32
39public class RingClosingUtils
40{
41
42//------------------------------------------------------------------------------
43
52 public static ArrayList<RingClosingAttractor> findAttractors(IAtomContainer mol)
53 {
54 ArrayList<RingClosingAttractor> attractors =
55 new ArrayList<RingClosingAttractor>();
56
57 for (IAtom atm : mol.atoms())
58 {
60 if (rca.isAttractor())
61 attractors.add(rca);
62 }
63
64 return attractors;
65 }
66
67//------------------------------------------------------------------------------
68
73 public static boolean areSameRingsSet(List<Ring> oldCmb,
74 List<Ring> ringsComb)
75 {
76 // Compare size
77 if (oldCmb.size() != ringsComb.size())
78 {
79 return false;
80 }
81
82 // Compare individual rings
83 int checkedRings = 0;
84 for (Ring rA : oldCmb)
85 {
86 Vertex headA = rA.getHeadVertex();
87 Vertex tailA = rA.getTailVertex();
88 for (Ring rB : ringsComb)
89 {
90 if (rA.getSize() != rB.getSize())
91 {
92 continue;
93 }
94 if (rB.contains(headA))
95 {
96 Vertex headB = rB.getHeadVertex();
97 Vertex tailB = rB.getTailVertex();
98 if ((headA == headB && tailA != tailB) ||
99 (headA == tailB && tailA != headB))
100 {
101 return false;
102 }
103 else if ((headA == headB && tailA == tailB) ||
104 (headA == tailB && tailA == headB))
105 {
106 checkedRings++;
107 }
108 }
109 }
110 }
111 if (oldCmb.size() != checkedRings)
112 {
113 return false;
114 }
115 return true;
116 }
117
118//------------------------------------------------------------------------------
119}
This class represents the closure of a ring in a spanning tree.
Definition: Ring.java:40
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
The RingClosingAttractor represent the available valence/connection that allows to close a ring.
boolean isAttractor()
Checks whether the constructed RingClosingAttractor does corresponds to a RingClosingAttractor in the...
Toolbox useful when dealing with Ring Closing Attractors and ring closures.
static boolean areSameRingsSet(List< Ring > oldCmb, List< Ring > ringsComb)
Compares two combinations of DENOPTIMRingss and evaluates whether these correspond to the same combin...
static ArrayList< RingClosingAttractor > findAttractors(IAtomContainer mol)
Looks for pseudoatoms representing the possibility of closing a ring: the so-called RingClosingAttrac...