$darkmode
DENOPTIM
ClusterableFragment.java
Go to the documentation of this file.
1package denoptim.fragmenter;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6import java.util.Set;
7
8import javax.vecmath.Point3d;
9
10import org.apache.commons.math3.ml.clustering.Clusterable;
11import org.jgrapht.graph.DefaultUndirectedGraph;
12import org.openscience.cdk.interfaces.IAtom;
13
14import denoptim.constants.DENOPTIMConstants;
15import denoptim.graph.AttachmentPoint;
16import denoptim.graph.FragIsomorphEdge;
17import denoptim.graph.FragIsomorphNode;
18import denoptim.graph.Fragment;
19
28public class ClusterableFragment implements Clusterable
29{
33 private Fragment frag;
34
38 private List<FragIsomorphNode> orderedNodes;
39
43 double[] allCoords;
44
45//------------------------------------------------------------------------------
46
53 {
54 this.frag = frag;
55 }
56
57//------------------------------------------------------------------------------
58
64 public void setOrderOfNodes(Collection<FragIsomorphNode> c)
65 {
66 orderedNodes = new ArrayList<FragIsomorphNode>(c);
67
68 allCoords = new double[orderedNodes.size()*3];
69 int i=-1;
71 {
72 i++;
73 allCoords[i] = node.getPoint3d().x;
74 i++;
75 allCoords[i] = node.getPoint3d().y;
76 i++;
77 allCoords[i] = node.getPoint3d().z;
78 }
79 }
80
81//------------------------------------------------------------------------------
82
91 public void setNaturalNodeOrder()
92 {
93 List<FragIsomorphNode> naturalOrder = new ArrayList<FragIsomorphNode>();
94 Set<FragIsomorphNode> nodeSet =
95 frag.getJGraphFragIsomorphism().vertexSet();
96 for (IAtom atm : frag.atoms())
97 {
98 for (FragIsomorphNode n : nodeSet)
99 {
100 if (n.getOriginal() == atm)
101 {
102 naturalOrder.add(n);
103 break;
104 }
105 }
106 }
108 {
109 for (FragIsomorphNode n : nodeSet)
110 {
111 if (n.getOriginal() == ap)
112 {
113 naturalOrder.add(n);
114 break;
115 }
116 }
117 }
118 setOrderOfNodes(naturalOrder);
119 }
120
121//------------------------------------------------------------------------------
122
129 protected void setCoordsVector(double[] coords)
130 {
131 this.allCoords = coords;
132 }
133
134//------------------------------------------------------------------------------
135
142 protected void setCoordsVector(Point3d[] pts)
143 {
144 this.allCoords = convertToCoordsVector(pts);
145 }
146
147//------------------------------------------------------------------------------
148
154 {
155 return frag;
156 }
157
158//------------------------------------------------------------------------------
159
164 protected DefaultUndirectedGraph<FragIsomorphNode, FragIsomorphEdge>
166 {
168 }
169
170//------------------------------------------------------------------------------
171
178 @Override
179 public double[] getPoint()
180 {
181 return allCoords;
182 }
183
184//------------------------------------------------------------------------------
185
192 public List<FragIsomorphNode> getOrderedNodes()
193 {
194 return orderedNodes;
195 }
196
197//------------------------------------------------------------------------------
198
206 public static double[] convertToCoordsVector(Point3d[] pts)
207 {
208 double[] coords = new double[pts.length*3];
209 for (int j=0; j<pts.length; j++)
210 {
211 int i = j*3;
212 coords[i] = pts[j].x;
213 coords[i+1] = pts[j].y;
214 coords[i+2] = pts[j].z;
215 }
216 return coords;
217 }
218
219//------------------------------------------------------------------------------
220
228 public static Point3d[] convertToPointArray(double[] coords)
229 {
230 Point3d[] pts = new Point3d[coords.length/3];
231 for (int j=0; j<coords.length/3; j++)
232 {
233 int i = j*3;
234 pts[j] = new Point3d(coords[i], coords[i+1], coords[i+2]);
235 }
236 return pts;
237 }
238
239//------------------------------------------------------------------------------
240
246 @Override
248 {
251 return clone;
252 }
253
254//------------------------------------------------------------------------------
255
262 {
263 Fragment copy = frag.clone();
264
266 int j=0;
267 for (FragIsomorphNode node : this.orderedNodes)
268 {
269 if (node.isAtm())
270 {
271 int atmId = frag.indexOf((IAtom) node.getOriginal());
272 copy.getAtom(atmId).setPoint3d(newCoords[j]);
273 } else {
274 int apId = frag.getIndexOfAP((AttachmentPoint) node.getOriginal());
275 copy.getAP(apId).setDirectionVector(newCoords[j]);
276 }
277 j++;
278 }
279 return copy;
280 }
281
282//------------------------------------------------------------------------------
283
284}
Represents a fragment that can be clustered based on the 3*N coordinate of atoms and attachment point...
double[] allCoords
Ordered list of coordinated reflecting the ordered list of atoms/APs.
List< FragIsomorphNode > getOrderedNodes()
Get the ordered list of nodes representing each either an atom or an attachment point is the alignmen...
void setNaturalNodeOrder()
Define the node order from the list of atoms and attachment points.
static double[] convertToCoordsVector(Point3d[] pts)
Converts an array of 3-dimensional points in a vector of coordinates in 3*N-dimensional space where c...
ClusterableFragment clone()
Returns a shallow copy where the vector of coordinates has a new reference.
void setCoordsVector(double[] coords)
Sets the coordinates of each atom and attachment point in this object.
static Point3d[] convertToPointArray(double[] coords)
Converts an array of 3*N-dimensional coordinates into an array of 3-dimensional points assuming coord...
Fragment frag
Reference to original fragment.
Fragment getOriginalFragment()
The original fragment used to construct an instance of this object.
List< FragIsomorphNode > orderedNodes
Ordered list of nodes determined by isomorphism.
ClusterableFragment(Fragment frag)
Constructor.
void setOrderOfNodes(Collection< FragIsomorphNode > c)
Sets the order of nodes (i.e., atoms/APs) to use for geometric comparison with other fragments,...
void setCoordsVector(Point3d[] pts)
Sets the coordinates of each atom and attachment point in this object.
DefaultUndirectedGraph< FragIsomorphNode, FragIsomorphEdge > getJGraphFragIsomorphism()
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
void setDirectionVector(Point3d dirVec)
Sets the end of the 3D vector defining the direction of the AP in 3D.
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
List< AttachmentPoint > getAttachmentPoints()
Definition: Fragment.java:1120
Fragment clone()
Returns a deep copy of this fragments.
Definition: Fragment.java:733
Iterable< IAtom > atoms()
Definition: Fragment.java:822
IAtom getAtom(int number)
Definition: Fragment.java:843
DefaultUndirectedGraph< FragIsomorphNode, FragIsomorphEdge > getJGraphFragIsomorphism()
Creates a graph representation of this fragment where both atoms and AttachmentPoints are represented...
Definition: Fragment.java:996
int indexOf(IAtom atom)
Definition: Fragment.java:850
int getIndexOfAP(AttachmentPoint ap)
Returns the position of the given AP in the list of APs of this vertex.
Definition: Vertex.java:949
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920