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;
83 boolean ignoreAPClasses)
100 int timeout,
boolean ignoreAPClasses)
103 Comparator<FragIsomorphNode> vComp =
new Comparator<FragIsomorphNode>()
110 String tmpLbl1 =
"ap";
111 String tmpLbl2 =
"ap";
116 return tmpLbl1.compareTo(tmpLbl2);
123 Comparator<FragIsomorphEdge> eComp =
new Comparator<FragIsomorphEdge>()
132 vf2 =
new VF2GraphIsomorphismInspector<>(
147 boolean result =
false;
148 final ExecutorService service = Executors.newSingleThreadExecutor();
149 Future<Boolean> future =
null;
151 future = service.submit(() -> {
152 return vf2.isomorphismExists();
154 result = future.get(
timeout, TimeUnit.MILLISECONDS);
155 }
catch (
final TimeoutException e) {
158 String fileName =
"denoptim_isomorphism_timedout_case.sdf";
159 File file =
new File(fileName);
160 System.err.println(
"WARNING: timeout reached when attempting "
161 +
"detection of isomerism between fragments saved to '"
162 + file.getAbsolutePath() +
"'. "
163 +
"When timeout is reaches, fragments are"
164 +
"considered to be non-isomorphic.");
165 List<Vertex> frags =
new ArrayList<Vertex>();
173 System.err.println(
"WARNING: could not write to '"
174 + fileName +
"'. Reporting fragments to STDERR:."
175 + System.getProperty(
"line.separator")
177 + System.getProperty(
"line.separator")
182 }
catch (
final Exception e) {
183 throw new RuntimeException(e);
192 public Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>>
getMappings()
194 Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>> mapping =
null;
195 final ExecutorService service = Executors.newSingleThreadExecutor();
196 Future<Iterator<GraphMapping<FragIsomorphNode, FragIsomorphEdge>>> fut =
199 fut = service.submit(() -> {
200 return vf2.getMappings();
202 mapping = fut.get(
timeout, TimeUnit.MILLISECONDS);
203 }
catch (
final TimeoutException e) {
206 String fileName =
"denoptim_isomorphism_timedout_case.sdf";
207 File file =
new File(fileName);
208 System.err.println(
"WARNING: timeout reached when attempting "
209 +
"detection of isomerism between fragments saved to '"
210 + file.getAbsolutePath() +
"'. "
211 +
"When timeout is reaches, fragments are"
212 +
"considered to be non-isomorphic.");
213 List<Vertex> frags =
new ArrayList<Vertex>();
221 System.err.println(
"WARNING: could not write to '"
222 + fileName +
"'. Reporting fragments to STDERR:."
223 + System.getProperty(
"line.separator")
225 + System.getProperty(
"line.separator")
230 }
catch (
final Exception e) {
231 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.
boolean isAtm
true if the original object was an atom.
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, boolean ignoreAPClasses)
Constructs a default inspector with a timeout runtime of 60 seconds.
boolean isomorphismExists()
Checks if an isomorphism exists between the two fragments.
VF2GraphIsomorphismInspector< FragIsomorphNode, FragIsomorphEdge > vf2
Implementation of the Vento-Foggia 2 algorithm.
FragmentIsomorphismInspector(Fragment fragA, Fragment fragB, int timeout, boolean ignoreAPClasses)
Constructs an inspector with a custom timeout limit.
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.