4import java.util.ArrayList;
5import java.util.Comparator;
6import java.util.Iterator;
8import java.util.concurrent.ExecutorService;
9import java.util.concurrent.Executors;
10import java.util.concurrent.Future;
11import java.util.concurrent.TimeUnit;
12import java.util.concurrent.TimeoutException;
14import org.jgrapht.GraphMapping;
15import org.jgrapht.alg.isomorphism.VF2GraphIsomorphismInspector;
17import denoptim.exception.DENOPTIMException;
18import denoptim.io.DenoptimIO;
59 VF2GraphIsomorphismInspector<FragIsomorphNode, FragIsomorphEdge>
vf2;
88 Comparator<FragIsomorphNode> vComp =
new Comparator<FragIsomorphNode>()
97 Comparator<FragIsomorphEdge> eComp =
new Comparator<FragIsomorphEdge>()
106 vf2 =
new VF2GraphIsomorphismInspector<>(
121 boolean result =
false;
122 final ExecutorService service = Executors.newSingleThreadExecutor();
123 Future<Boolean> future =
null;
125 future = service.submit(() -> {
126 return vf2.isomorphismExists();
128 result = future.get(
timeout, TimeUnit.MILLISECONDS);
129 }
catch (
final TimeoutException e) {
132 String fileName =
"denoptim_isomorphism_timedout_case.sdf";
133 File file =
new File(fileName);
134 System.err.println(
"WARNING: timeout reached when attempting "
135 +
"detection of isomerism between fragments saved to '"
136 + file.getAbsolutePath() +
"'. "
137 +
"When timeout is reaches, fragments are"
138 +
"considered to be non-isomorphic.");
139 List<Vertex> frags =
new ArrayList<Vertex>();
147 System.err.println(
"WARNING: could not write to '"
148 + fileName +
"'. Reporting fragments to STDERR:."
149 + System.getProperty(
"line.separator")
151 + System.getProperty(
"line.separator")
156 }
catch (
final Exception e) {
157 throw new RuntimeException(e);
166 public Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>>
getMappings()
168 Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>> mapping =
null;
169 final ExecutorService service = Executors.newSingleThreadExecutor();
170 Future<Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>>> fut =
173 fut = service.submit(() -> {
174 return vf2.getMappings();
176 mapping = fut.get(
timeout, TimeUnit.MILLISECONDS);
177 }
catch (
final TimeoutException e) {
180 String fileName =
"denoptim_isomorphism_timedout_case.sdf";
181 File file =
new File(fileName);
182 System.err.println(
"WARNING: timeout reached when attempting "
183 +
"detection of isomerism between fragments saved to '"
184 + file.getAbsolutePath() +
"'. "
185 +
"When timeout is reaches, fragments are"
186 +
"considered to be non-isomorphic.");
187 List<Vertex> frags =
new ArrayList<Vertex>();
195 System.err.println(
"WARNING: could not write to '"
196 + fileName +
"'. Reporting fragments to STDERR:."
197 + System.getProperty(
"line.separator")
199 + System.getProperty(
"line.separator")
204 }
catch (
final Exception e) {
205 throw new RuntimeException(e);
String label
Bond order or name used to identify the edge type.
String label
Elemental symbol or name used to identify the node content.
Class representing a continuously connected portion of chemical object holding attachment points.
DefaultUndirectedGraph< FragIsomorphNode, FragIsomorphEdge > getJGraphFragIsomorphism()
Creates a graph representation of this fragment where both atoms and AttachmentPoints are represented...
String toJson()
Produces a string that represents this vertex and that adheres to the JSON format.
int timeout
The maximum time we give the VF2 algorithm (seconds)
boolean reportTimeoutIncidents
Flag indicating if we print earning in case of timeout or not.
Fragment fragA
One fragment being analyzed.
Fragment fragB
The other fragment being analyzed.
FragmentIsomorphismInspector(Fragment fragA, Fragment fragB, int timeout)
Constructs an inspector with a custom timeout limiet.
boolean isomorphismExists()
Checks if an isomorphism exists between the two fragments.
VF2GraphIsomorphismInspector< FragIsomorphNode, FragIsomorphEdge > vf2
Implementation of the Vento-Foggia 2 algorithm.
Iterator< GraphMapping< FragIsomorphNode, FragIsomorphEdge > > getMappings()
FragmentIsomorphismInspector(Fragment fragA, Fragment fragB)
Constructs a default inspector with a timeout runtime of 60 seconds.
Utility methods for input/output.
static void writeVertexesToSDF(File file, List< Vertex > vertexes, boolean append)
Write a list of vertexes to file.