23import java.io.BufferedReader;
24import java.io.BufferedWriter;
26import java.io.FileNotFoundException;
27import java.io.FileReader;
28import java.io.FileWriter;
29import java.io.IOException;
30import java.io.PrintWriter;
31import java.io.StringWriter;
32import java.text.DateFormat;
33import java.text.SimpleDateFormat;
34import java.util.ArrayList;
35import java.util.Arrays;
36import java.util.Collections;
37import java.util.Comparator;
39import java.util.HashMap;
40import java.util.HashSet;
41import java.util.Hashtable;
42import java.util.LinkedHashMap;
46import java.util.SortedSet;
47import java.util.TreeSet;
48import java.util.logging.Level;
49import java.util.logging.Logger;
51import org.apache.commons.io.FilenameUtils;
52import org.jmol.adapter.smarter.SmarterJmolAdapter;
53import org.jmol.viewer.Viewer;
54import org.openscience.cdk.AtomContainerSet;
55import org.openscience.cdk.CDKConstants;
56import org.openscience.cdk.ChemFile;
57import org.openscience.cdk.ChemObject;
58import org.openscience.cdk.exception.CDKException;
59import org.openscience.cdk.interfaces.IAtomContainer;
60import org.openscience.cdk.interfaces.IAtomContainerSet;
61import org.openscience.cdk.interfaces.IChemFile;
62import org.openscience.cdk.interfaces.IChemObject;
63import org.openscience.cdk.interfaces.IChemObjectBuilder;
64import org.openscience.cdk.io.FormatFactory;
65import org.openscience.cdk.io.ISimpleChemObjectReader;
66import org.openscience.cdk.io.MDLV2000Reader;
67import org.openscience.cdk.io.MDLV2000Writer;
68import org.openscience.cdk.io.Mol2Writer;
69import org.openscience.cdk.io.ReaderFactory;
70import org.openscience.cdk.io.SDFWriter;
71import org.openscience.cdk.io.XYZWriter;
72import org.openscience.cdk.io.formats.CIFFormat;
73import org.openscience.cdk.io.formats.IChemFormat;
74import org.openscience.cdk.silent.SilentChemObjectBuilder;
75import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
77import com.google.gson.Gson;
78import com.google.gson.JsonSyntaxException;
79import com.google.gson.reflect.TypeToken;
81import denoptim.constants.DENOPTIMConstants;
82import denoptim.exception.DENOPTIMException;
83import denoptim.files.FileFormat;
84import denoptim.files.FileUtils;
85import denoptim.files.UndetectedFileFormatException;
86import denoptim.fragmenter.BridgeHeadFindingRule;
87import denoptim.fragspace.FragmentSpace;
88import denoptim.graph.APClass;
89import denoptim.graph.AttachmentPoint;
90import denoptim.graph.Candidate;
91import denoptim.graph.CandidateLW;
92import denoptim.graph.DGraph;
93import denoptim.graph.Template;
94import denoptim.graph.Vertex;
95import denoptim.graph.Vertex.BBType;
96import denoptim.json.DENOPTIMgson;
97import denoptim.logging.StaticLogger;
98import denoptim.molecularmodeling.ThreeDimTreeBuilder;
99import denoptim.programs.fragmenter.CuttingRule;
100import denoptim.utils.GraphConversionTool;
101import denoptim.utils.GraphEdit;
102import denoptim.utils.GraphUtils;
103import denoptim.utils.Randomizer;
119 public static final String
FS = System.getProperty(
"file.separator");
124 public static final String
NL = System.getProperty(
"line.separator");
126 private static final IChemObjectBuilder
builder =
127 SilentChemObjectBuilder.getInstance();
144 File file =
new File(pathname);
190 data = graphs.get(0);
201 data = graphs.get(0);
217 + format +
"' cannot be loaded yet. Please, contact"
218 +
"the development team.");
241 ArrayList<Candidate> cands =
new ArrayList<Candidate>();
243 String genSummaryParentDir = file.getParent();
244 for (String candPathname : pathnames)
246 File candFile =
new File(candPathname);
247 if (candFile.exists())
250 }
else if (genSummaryParentDir!=
null) {
253 String runFolderPathname =
254 candFile.getParentFile()
256 if (runFolderPathname==
null)
258 +
"folder for '"+ genSummaryParentDir +
"'");
260 String genAndMolPath = candFile.getAbsolutePath()
261 .substring(runFolderPathname.length());
264 genSummaryParentDir+genAndMolPath)).
get(0));
284 throws IOException, CDKException
286 List<IAtomContainer> results =
null;
288 FileReader formatReader =
new FileReader(file);
289 IChemFormat chemFormat =
new FormatFactory().guessFormat(
290 new BufferedReader(formatReader));
291 formatReader.close();
293 if (chemFormat instanceof CIFFormat)
314 Map<String, Object> info =
new Hashtable<String, Object>();
315 info.put(
"adapter",
new SmarterJmolAdapter());
316 info.put(
"isApp",
false);
317 info.put(
"silent",
"");
318 Viewer v =
new Viewer(info);
319 v.loadModelFromFile(
null, file.getAbsolutePath(),
null,
null,
320 false,
null,
null,
null, 0,
" ");
322 v.scriptWait(
"write " + tmp +
" as sdf");
327 FileReader fileReader =
new FileReader(file);
328 ReaderFactory readerFact =
new ReaderFactory();
329 ISimpleChemObjectReader reader = readerFact.createReader(fileReader);
330 IChemFile chemFile = (IChemFile) reader.read(
331 (IChemObject)
new ChemFile());
332 results = ChemFileManipulator.getAllAtomContainers(chemFile);
348 public static ArrayList<IAtomContainer>
readSDFFile(String fileName)
350 MDLV2000Reader mdlreader =
null;
351 ArrayList<IAtomContainer> lstContainers =
new ArrayList<>();
354 mdlreader =
new MDLV2000Reader(
new FileReader(
new File(fileName)));
355 ChemFile chemFile = (ChemFile) mdlreader.read((ChemObject)
new ChemFile());
356 lstContainers.addAll(
357 ChemFileManipulator.getAllAtomContainers(chemFile));
358 }
catch (CDKException | IOException cdke) {
362 if (mdlreader !=
null) {
365 }
catch (IOException ioe) {
370 if (lstContainers.isEmpty()) {
374 return lstContainers;
406 ArrayList<Vertex> lst =
new ArrayList<Vertex>();
424 if (FilenameUtils.getExtension(file.getName()).equals(
""))
426 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
478 file.getAbsolutePath());
479 allVertexes.addAll(vertexes);
480 writeData(file.getAbsolutePath(), writer.toJson(allVertexes),
false);
482 writeData(file.getAbsolutePath(), writer.toJson(vertexes),
false);
499 List<Vertex> lst =
new ArrayList<Vertex>();
515 List<Vertex> vertexes,
boolean append)
518 List<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
521 lst.add(v.getIAtomContainer());
537 List<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
551 public static void writeSDFFile(String fileName, List<IAtomContainer> mols)
566 public static void writeSDFFile(String fileName, List<IAtomContainer> mols,
569 SDFWriter sdfWriter =
null;
571 IAtomContainerSet molSet =
new AtomContainerSet();
572 for (
int idx = 0; idx < mols.size(); idx++) {
573 molSet.addAtomContainer(mols.get(idx));
575 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName),append));
576 sdfWriter.write(molSet);
577 }
catch (CDKException | IOException cdke) {
581 if (sdfWriter !=
null) {
584 }
catch (IOException ioe) {
602 SDFWriter sdfWriter =
null;
604 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName), append));
605 sdfWriter.write(mol);
606 }
catch (CDKException | IOException cdke) {
610 if (sdfWriter !=
null) {
613 }
catch (IOException ioe) {
623 Mol2Writer mol2Writer =
null;
625 mol2Writer =
new Mol2Writer(
new FileWriter(
new File(fileName), append));
626 mol2Writer.write(mol);
627 }
catch (CDKException cdke) {
629 }
catch (IOException ioe) {
633 if (mol2Writer !=
null) {
636 }
catch (IOException ioe) {
646 XYZWriter xyzWriter =
null;
648 xyzWriter =
new XYZWriter(
new FileWriter(
new File(fileName), append));
649 xyzWriter.write(mol);
650 }
catch (CDKException cdke) {
652 }
catch (IOException ioe) {
656 if (xyzWriter !=
null) {
659 }
catch (IOException ioe) {
678 FileWriter fw =
null;
680 fw =
new FileWriter(
new File(fileName), append);
681 for (
int i = 0; i < smiles.length; i++) {
682 fw.write(smiles[i] +
NL);
685 }
catch (IOException ioe) {
692 }
catch (IOException ioe) {
711 FileWriter fw =
null;
713 fw =
new FileWriter(
new File(fileName), append);
714 fw.write(smiles +
NL);
716 }
catch (IOException ioe) {
723 }
catch (IOException ioe) {
739 public static void writeData(String fileName, String data,
boolean append)
741 FileWriter fw =
null;
743 fw =
new FileWriter(
new File(fileName), append);
746 }
catch (IOException ioe) {
753 }
catch (IOException ioe) {
773 List<String> propNames =
new ArrayList<String>(Arrays.asList(
777 List<String> optionalPropNames =
new ArrayList<String>(Arrays.asList(
783 propNames.addAll(optionalPropNames);
785 file.getAbsolutePath(), propNames);
787 List<CandidateLW> items =
new ArrayList<CandidateLW>();
788 for (Map<String, Object> props : propsPerItem)
796 Object nameObj = props.get(CDKConstants.TITLE);
800 + CDKConstants.TITLE +
" is null!");
803 nameObj.toString(),file.getAbsolutePath());
805 for (String propName : optionalPropNames)
807 Object obj = props.get(propName);
813 item.
setFitness(Double.parseDouble(obj.toString()));
825 item.
setLevel(Integer.parseInt(obj.toString()));
847 double[] vals =
new double[4];
848 ArrayList<String> txt =
readList(file.getAbsolutePath());
849 for (String line : txt) {
850 if (line.trim().length() < 8) {
854 String key = line.toUpperCase().trim().substring(0, 8);
857 vals[0] = Double.parseDouble(line.split(
"\\s+")[1]);
861 vals[1] = Double.parseDouble(line.split(
"\\s+")[1]);
865 vals[2] = Double.parseDouble(line.split(
"\\s+")[1]);
869 vals[3] = Double.parseDouble(line.split(
"\\s+")[1]);
889 List<String> vals =
new ArrayList<String>();
890 ArrayList<String> txt =
readList(file.getAbsolutePath());
891 for (String line : txt)
893 if (!line.contains(
FS))
896 String[] words = line.trim().split(
"\\s+");
897 if (words.length < 5)
922 List<CandidateLW> members =
new ArrayList<CandidateLW>();
923 List<String> txt =
readList(file.getAbsolutePath());
926 for (
int i=1; i<txt.size(); i++)
928 String line = txt.get(i);
933 if (line.startsWith(
"#"))
939 String[] words = line.trim().split(
"\\s+");
940 String pathname =
"nofile";
941 if (words.length >= 5)
946 member.
setFitness(Double.parseDouble(words[3]));
961 public static ArrayList<String>
readList(String fileName)
977 public static ArrayList<String>
readList(String fileName,
979 ArrayList<String> lst =
new ArrayList<>();
980 BufferedReader br =
null;
983 br =
new BufferedReader(
new FileReader(fileName));
984 while ((line = br.readLine()) !=
null) {
985 if (line.trim().length() == 0) {
988 lst.add(line.trim());
990 }
catch (IOException ioe) {
997 }
catch (IOException ioe) {
1002 if (lst.isEmpty() && !allowEmpty) {
1019 StringBuilder sb =
new StringBuilder();
1020 BufferedReader br =
null;
1023 br =
new BufferedReader(
new FileReader(fileName));
1024 while ((line = br.readLine()) !=
null) {
1025 sb.append(line).append(
NL);
1027 }
catch (IOException ioe) {
1034 }
catch (IOException ioe) {
1039 return sb.toString();
1055 List<Map<String,Object>> results =
new ArrayList<Map<String,Object>>();
1057 for (IAtomContainer iac : iacs)
1059 Map<String,Object> properties =
new HashMap<String,Object>();
1060 for (String propName : propNames)
1062 properties.put(propName, iac.getProperty(propName));
1064 results.add(properties);
1080 StringWriter stringWriter =
new StringWriter();
1081 MDLV2000Writer mw =
null;
1083 mw =
new MDLV2000Writer(stringWriter);
1085 }
catch (CDKException cdke) {
1092 }
catch (IOException ioe) {
1097 String MoleculeString = stringWriter.toString();
1101 String Moleculelines[] = MoleculeString.split(
"\\r?\\n");
1103 StringBuilder sb =
new StringBuilder(1024);
1104 sb.append(
"var molFile = '");
1105 for (
int i = 0; i < Moleculelines.length; i++) {
1106 sb.append(Moleculelines[i]);
1110 return sb.toString();
1116 Set<APClass> allCLasses =
new HashSet<APClass>();
1121 allCLasses.add(ap.getAPClass());
1126 System.out.println(
"Could not read data from '" + fragLib +
"'. "
1127 +
"Cause: " + e.getMessage());
1144 HashMap<
APClass, ArrayList<APClass>> cpMap,
1145 HashMap<APClass, APClass> capMap,
1147 DateFormat dateFormat =
new SimpleDateFormat(
"dd/MM/yy HH:mm:ss");
1148 Date date =
new Date();
1149 String dateStr = dateFormat.format(date);
1151 StringBuilder sb =
new StringBuilder();
1153 sb.append(
" Compatibility matrix data").append(
NL);
1155 sb.append(
" Written by DENOPTIM-GUI on ").append(dateStr).append(
NL);
1157 sb.append(
" APCLass Compatibility rules").append(
NL);
1158 SortedSet<APClass> keysCPMap =
new TreeSet<APClass>();
1159 keysCPMap.addAll(cpMap.keySet());
1160 for (
APClass srcAPC : keysCPMap) {
1162 sb.append(srcAPC).append(
" ");
1163 for (
int i = 0; i < cpMap.get(srcAPC).size(); i++) {
1164 APClass trgAPC = cpMap.get(srcAPC).get(i);
1166 if (i != (cpMap.get(srcAPC).size() - 1)) {
1175 sb.append(
" Capping rules").append(
NL);
1176 SortedSet<APClass> keysCap =
new TreeSet<APClass>();
1177 keysCap.addAll(capMap.keySet());
1180 sb.append(apc).append(
" ").append(capMap.get(apc)).append(
NL);
1184 sb.append(
" Forbidden ends").append(
NL);
1185 SortedSet<APClass> sortedFE =
new TreeSet<APClass>();
1186 sortedFE.addAll(ends);
1187 for (
APClass apc : sortedFE) {
1189 sb.append(apc).append(
" ").append(
NL);
1207 ArrayList<APClass>> compatMap,
1208 HashMap<APClass, APClass> cappingMap, Set<APClass> forbiddenEndList)
1211 BufferedReader br =
null;
1214 br =
new BufferedReader(
new FileReader(fileName));
1215 while ((line = br.readLine()) !=
null) {
1216 if (line.trim().length() == 0) {
1225 String str[] = line.split(
"\\s+");
1226 if (str.length < 3) {
1227 String err =
"Incomplete APClass compatibility line '"
1233 ArrayList<APClass> trgAPCs =
new ArrayList<APClass>();
1234 for (String s : str[2].split(
","))
1238 compatMap.put(srcAPC, trgAPCs);
1241 String str[] = line.split(
"\\s+");
1242 if (str.length != 3) {
1243 String err =
"Incomplete capping line '"
1249 cappingMap.put(srcAPC, trgAPC);
1251 if (line.startsWith(
1253 String str[] = line.split(
"\\s+");
1254 if (str.length != 2) {
1255 for (
int is = 1; is < str.length; is++) {
1256 forbiddenEndList.add(
1266 }
catch (NumberFormatException | IOException nfe) {
1273 }
catch (IOException ioe) {
1278 if (compatMap.isEmpty()) {
1279 String err =
"No reaction compatibility data found in file: ";
1301 HashMap<
APClass, ArrayList<APClass>> rcCompatMap)
1303 BufferedReader br =
null;
1306 br =
new BufferedReader(
new FileReader(fileName));
1307 while ((line = br.readLine()) !=
null) {
1308 if (line.trim().length() == 0) {
1317 String str[] = line.split(
"\\s+");
1318 if (str.length < 3) {
1319 String err =
"Incomplete reaction compatibility data.";
1325 String strRcn[] = str[2].split(
",");
1326 for (
int i = 0; i < strRcn.length; i++) {
1327 strRcn[i] = strRcn[i].trim();
1330 if (rcCompatMap.containsKey(srcAPC)) {
1331 rcCompatMap.get(srcAPC).add(trgAPC);
1333 ArrayList<APClass> list =
new ArrayList<APClass>();
1335 rcCompatMap.put(srcAPC, list);
1338 if (rcCompatMap.containsKey(trgAPC)) {
1339 rcCompatMap.get(trgAPC).add(srcAPC);
1341 ArrayList<APClass> list =
new ArrayList<APClass>();
1343 rcCompatMap.put(trgAPC, list);
1348 }
catch (NumberFormatException | IOException nfe) {
1355 }
catch (IOException ioe) {
1360 if (rcCompatMap.isEmpty()) {
1361 String err =
"No reaction compatibility data found in file: ";
1400 String filename = file.getAbsolutePath();
1401 ArrayList<Candidate> candidates =
new ArrayList<>();
1402 ArrayList<IAtomContainer> iacs =
readSDFFile(file.getAbsolutePath());
1406 if (file.getParentFile()!=
null
1407 && file.getParentFile().getName().startsWith(
1410 String genFolderName = file.getParentFile().getName();
1411 genID = Integer.valueOf(genFolderName.substring(
1415 for (IAtomContainer iac : iacs) {
1420 candidates.add(cand);
1435 List<Candidate> popMembers,
boolean append)
1438 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1440 file =
new File(file.getAbsoluteFile() +
"."
1443 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
1446 lst.add(g.getFitnessProviderOutputRepresentation());
1464 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1466 file =
new File(file.getAbsoluteFile() +
"."
1470 candidate.getFitnessProviderOutputRepresentation(), append);
1485 ArrayList<GraphEdit> graphEditTasks =
new ArrayList<>();
1488 BufferedReader br =
null;
1491 br =
new BufferedReader(
new FileReader(fileName));
1492 graphEditTasks = reader.fromJson(br,
1493 new TypeToken<ArrayList<GraphEdit>>(){}.getType());
1495 catch (FileNotFoundException fnfe)
1499 catch (JsonSyntaxException jse)
1501 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1502 if (jse.getMessage().contains(msg))
1509 br =
new BufferedReader(
new FileReader(fileName));
1511 catch (FileNotFoundException fnfe)
1514 }
catch (IOException ioe)
1518 GraphEdit graphEditTask = reader.fromJson(br,
1520 graphEditTasks.add(graphEditTask);
1522 jse.printStackTrace();
1524 +
"that defines a graph enditing task.",jse);
1534 }
catch (IOException ioe) {
1539 return graphEditTasks;
1579 inFile.getAbsolutePath());
1583 inFile.getAbsolutePath());
1588 +
"JSON format instead.");
1592 inFile.getAbsolutePath());
1595 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
1598 for (
Vertex v : vertexes)
1602 graphs.add(((
Template)v).getInnerGraph());
1605 System.out.println(
"WARNING: Reading graphs from "
1607 +
"templates' inner graphs. Importing "
1608 + graphs.size() +
" graphs "
1609 +
"from " + vertexes.size() +
" vertexes.");
1613 throw new Exception(
"Format '" + format +
"' could not be used "
1614 +
"to read graphs from file '" + inFile +
"'.");
1630 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1633 for (IAtomContainer mol : mols)
1703 +
"files containing graphs must include the "
1706 String msg =
"Attempt to load graph form "
1707 +
"SDF that has no '" + DENOPTIMConstants.GRAPHJSONTAG
1711 msg = msg +
" Check molecule " + molId;
1712 if (!fileName.isEmpty())
1714 msg = msg +
" in the SDF file '" + fileName +
"'";
1721 String js = json.toString();
1725 }
catch (Exception e)
1727 String msg = e.getMessage();
1730 msg = msg +
" Check molecule " + molId;
1731 if (!fileName.isEmpty())
1733 msg = msg +
" in the SDF file '" + fileName +
"'";
1757 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1758 BufferedReader br =
null;
1761 br =
new BufferedReader(
new FileReader(fileName));
1762 while ((line = br.readLine()) !=
null) {
1763 if (line.trim().length() == 0) {
1775 }
catch (Throwable t) {
1776 String msg =
"Cannot convert string to DENOPTIMGraph. "
1777 +
"Check line '" + line.trim() +
"'";
1778 logger.log(Level.SEVERE, msg);
1783 }
catch (IOException ioe) {
1784 String msg =
"Cannot read file " + fileName;
1785 logger.log(Level.SEVERE, msg);
1792 }
catch (IOException ioe) {
1813 ArrayList<Vertex> result =
new ArrayList<Vertex>();
1816 BufferedReader br =
null;
1819 br =
new BufferedReader(
new FileReader(fileName));
1820 result = reader.fromJson(br,
1821 new TypeToken<ArrayList<Vertex>>(){}.getType());
1823 catch (FileNotFoundException fnfe)
1827 catch (JsonSyntaxException jse)
1829 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1830 if (jse.getMessage().contains(msg))
1837 br =
new BufferedReader(
new FileReader(fileName));
1839 catch (FileNotFoundException fnfe)
1842 }
catch (IOException ioe)
1850 + fileName +
"'.", jse);
1860 }
catch (IOException ioe) {
1879 ArrayList<DGraph> list_of_graphs =
new ArrayList<DGraph>();
1882 BufferedReader br =
null;
1885 br =
new BufferedReader(
new FileReader(fileName));
1886 list_of_graphs = reader.fromJson(br,
1887 new TypeToken<ArrayList<DGraph>>(){}.getType());
1889 catch (FileNotFoundException fnfe)
1893 catch (JsonSyntaxException jse)
1895 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1896 if (jse.getMessage().contains(msg))
1903 br =
new BufferedReader(
new FileReader(fileName));
1905 catch (FileNotFoundException fnfe)
1908 }
catch (IOException ioe)
1913 list_of_graphs.add(g);
1916 +
"JSON '" + fileName +
"'", jse);
1926 }
catch (IOException ioe) {
1931 return list_of_graphs;
1948 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1950 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
1981 List<DGraph> modGraphs, Logger logger,
Randomizer randomizer)
1984 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1986 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2015 List<DGraph> graphs, Logger logger,
Randomizer randomizer)
2033 boolean append,
boolean make3D, Logger logger,
Randomizer randomizer)
2036 List<DGraph> lst =
new ArrayList<>(1);
2052 boolean append, Logger logger,
Randomizer randomizer)
2055 ArrayList<DGraph> lst =
new ArrayList<>(1);
2071 List<DGraph> graphs,
boolean append,
2090 List<DGraph> modGraphs,
boolean append,
boolean make3D,
2093 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
2094 for (
DGraph g : modGraphs)
2097 IAtomContainer iac =
builder.newAtomContainer();
2102 }
catch (Throwable t) {
2103 t.printStackTrace();
2104 logger.log(Level.WARNING,
"Couldn't make 3D-tree "
2105 +
"representation: " + t.getMessage());
2127 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
2145 writeData(file.getAbsolutePath(), writer.toJson(graphs),
false);
2162 writeData(file.getAbsolutePath(), writer.toJson(graphs), append);
2178 writeData(fileName, graph.toString(), append);
2192 Map<File, FileFormat> map =
new LinkedHashMap<File, FileFormat>();
2203 String[] parts = line.split(
"\\s+");
2204 String ffStr = parts[0];
2209 }
catch (Exception e)
2212 +
"' to a known file format.");
2214 String fileName = line.substring(ffStr.length()).trim();
2217 map.put(
new File(fileName), ff);
2223 +
"fetch list of recent files.", e);
2224 map =
new HashMap<File, FileFormat>();
2248 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2254 file.getAbsolutePath(),bbt);
2259 file.getAbsolutePath());
2263 ArrayList<DGraph> lstGraphs =
2265 for (
DGraph g : lstGraphs)
2274 ArrayList<DGraph> lstGraphs2 =
2276 for (
DGraph g : lstGraphs2)
2286 +
"' could not be used to "
2287 +
"read in vertices from file '" + file +
"'.");
2304 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2317 +
" in file " + fileName,e);
2345 LinkedHashMap<String, String> allFormulae =
new LinkedHashMap<String,String>();
2346 BufferedReader buffRead =
null;
2349 buffRead =
new BufferedReader(
new FileReader(file));
2350 String lineAll =
null;
2351 String refcode =
"";
2352 String formula =
"";
2353 while ((lineAll = buffRead.readLine()) !=
null)
2355 String[] lineArgs = lineAll.split(
":");
2357 if (lineArgs[0].equals(
"REFCODE"))
2358 refcode = lineArgs[1].trim();
2361 if (lineArgs[0].equals(
" Formula"))
2363 formula = lineArgs[1].trim();
2365 allFormulae.put(refcode,formula);
2371 }
catch (FileNotFoundException fnf) {
2373 }
catch (IOException ioex) {
2377 if (buffRead !=
null)
2379 }
catch (IOException e) {
2403 ArrayList<String> cutRulLines =
new ArrayList<String>();
2407 while ((line = reader.readLine()) !=
null)
2410 cutRulLines.add(line.trim());
2412 }
catch (IOException e)
2420 }
catch (IOException e)
2441 ArrayList<String> allLines =
readList(file.getAbsolutePath());
2444 ArrayList<String> cutRulLines =
new ArrayList<String>();
2446 .filter(line -> line.trim().startsWith(
2448 .forEach(line -> cutRulLines.add(line.trim()));
2451 + file.getAbsolutePath()+
"'");
2472 Set<Integer> usedPriorities =
new HashSet<Integer>();
2473 for (
int i = 0; i<cutRulLines.size(); i++)
2475 String[] words = cutRulLines.get(i).split(
"\\s+");
2476 String name = words[1];
2477 if (words.length < 6)
2480 +
" Found " + words.length +
" parts inctead of 6."
2481 +
"Check line '" + cutRulLines.get(i) +
"'"
2482 +
"in " + source +
".");
2486 ArrayList<String> opts =
new ArrayList<String>();
2487 if (words.length >= 7)
2489 for (
int wi=6; wi<words.length; wi++)
2491 opts.add(words[wi]);
2495 int priority = Integer.parseInt(words[2]);
2496 if (usedPriorities.contains(priority))
2499 +
" Duplicate priority index " + priority +
". "
2500 +
"Check line '" + cutRulLines.get(i) +
"'"
2501 +
"in " + source +
".");
2503 usedPriorities.add(priority);
2516 Collections.sort(cutRules,
new Comparator<CuttingRule>() {
2538 StringBuilder sb =
new StringBuilder();
2542 sb.append(r.getName()).append(
" ");
2543 sb.append(r.getPriority()).append(
" ");
2544 sb.append(r.getSMARTSAtom0()).append(
" ");
2545 sb.append(r.getSMARTSAtom1()).append(
" ");
2546 sb.append(r.getSMARTSBnd()).append(
" ");
2547 if (r.getOptions()!=
null)
2549 for (String opt : r.getOptions())
2550 sb.append(opt).append(
" ");
2554 writeData(file.getAbsolutePath(), sb.toString(),
false);
2569 PrintWriter pw =
null;
2572 fw =
new FileWriter(f1,
true);
2573 bw =
new BufferedWriter(fw);
2574 pw =
new PrintWriter(bw);
2575 for (File inFile : files)
2578 BufferedReader br =
null;
2581 fr =
new FileReader(inFile);
2582 br =
new BufferedReader(fr);
2584 while ((line = br.readLine()) !=
null)
2612 List<BridgeHeadFindingRule> rules =
null;
2613 BufferedReader br =
null;
2615 br =
new BufferedReader(
new FileReader(fileName));
2618 catch (FileNotFoundException fnfe)
2621 }
catch (IOException ioe)
2632 }
catch (IOException ioe) {
2651 BufferedReader br)
throws IOException
2653 List<BridgeHeadFindingRule> rules =
new ArrayList<>();
2657 rules = reader.fromJson(br,
2658 new TypeToken<ArrayList<BridgeHeadFindingRule>>(){}.getType());
General set of constants used in DENOPTIM.
static final String GRAPHTAG
SDF tag containing graph encoding.
static final File RECENTFILESLIST
List of recent files.
static final String APCMAPIGNORE
Keyword identifying compatibility matrix file lines with comments.
static final String PROVENANCE
SDF tag containing provenance data for a graph.
static final String APCMAPCAPPING
Keyword identifying compatibility matrix file lines with capping rules.
static final String GRAPHLEVELTAG
SDF tag defining the graph generating level in an FSE run.
static final String UNIQUEIDTAG
SDF tag containing the unique identifier of a candidate.
static final String GAGENDIRNAMEROOT
Prefix for generation folders.
static final String CUTRULKEYWORD
Keyword that identifies rows defining cutting rules in files collecting cutting rules.
static final String GRAPHJSONTAG
SDF tag containing graph encoding in JSON format.
static final String APCMAPFORBIDDENEND
Keyword identifying compatibility matrix file lines with forbidden ends.
static final String MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final String APCMAPCOMPRULE
Keyword identifying compatibility matrix file lines with APClass compatibility rules.
static final String FITNESSTAG
SDF tag containing the fitness of a candidate.
static boolean checkExists(String fileName)
static FileFormat detectFileFormat(File inFile)
Inspects a file/folder and tries to detect if there is one of the data sources that is recognized by ...
static String getTempFolder()
Looks for a writable location where to put temporary files and returns an absolute pathname to the fo...
Class defining a space of building blocks.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
A candidate is the combination of a denoptim graph with molecular representation and may include also...
void setSDFFile(String molFile)
void setGeneration(int genId)
A light-weight candidate is a very low-demanding collection of data upon a specific candidate item.
void setFitness(double fitness)
void setError(String error)
void setLevel(int lev)
Sets level that generated this graph in a fragment space exploration experiment.
void setGeneratingSource(String source)
Container for the list of vertices and the edges that connect them.
static DGraph fromJson(String json)
Reads a JSON string and returns an instance of this class.
void setInnerGraph(DGraph innerGraph)
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
static Vertex parseVertexFromSDFFormat(IAtomContainer mol, Gson reader, BBType bbt)
Created a Vertex from the SDF representation, i.e., from an IAtomContainer.
static Vertex fromJson(String json)
Utility methods for input/output.
static ArrayList< Candidate > readCandidates(File file)
Reads SDF files that represent one or more tested candidates.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes)
Writes vertexes to file.
static File writeGraphToFile(File file, FileFormat format, DGraph graph, Logger logger, Randomizer randomizer)
Writes the a graph to file.
static LinkedHashMap< String, String > readCSDFormulae(File file)
Read molecular formula from TXT data representation produced by Cambridge Structural Database tools (...
static List< Candidate > readGenerationFromSummary(File file)
Reads a FileFormat#GENSUMMARY file and searches all the files defining each member of the population.
static void readCuttingRules(ArrayList< String > cutRulLines, List< CuttingRule > cutRules, String source)
Read cutting rules from a properly formatted text file.
static void readRCCompatibilityMatrix(String fileName, HashMap< APClass, ArrayList< APClass > > rcCompatMap)
Reads the APclass compatibility matrix for ring-closing connections (the RC-CPMap).
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile, FileFormat format)
Reads a list of DGraphs from file.
static List< String > readPopulationMemberPathnames(File file)
Read the pathnames to the population members from a FileFormat#GENSUMMARY file.
static void writeSDFFile(String fileName, IAtomContainer mol, boolean append)
Writes an IAtomContainer to SDF file.
static void writeGraphToFile(String fileName, DGraph graph, boolean append)
Writes the string representation of a graph to file.
static void writeGraphToSDF(File file, DGraph graph, boolean append, Logger logger, Randomizer randomizer)
Writes the graph to SDF file.
static void writeSDFFile(String fileName, List< IAtomContainer > mols)
Writes IAtomContainers to SDF file.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
static void readCuttingRules(File file, List< CuttingRule > cutRules)
Read cutting rules from a properly formatted text file.
static DGraph readGraphFromSDFileIAC(IAtomContainer mol, int molId, String fileName)
Converts an atom container read in from an SDF file into a graph, if possible.
static void writeXYZFile(String fileName, IAtomContainer mol, boolean append)
static ArrayList< Vertex > readDENOPTIMVertexesFromJSONFile(String fileName)
Reads a list of Vertexes from a JSON file.
static DGraph readGraphFromSDFileIAC(IAtomContainer mol)
Converts an atom container read in from an SDF file into a graph, if possible.
static final IChemObjectBuilder builder
static Map< File, FileFormat > readRecentFilesMap()
Reads the file defined in DENOPTIMConstants#RECENTFILESLIST and makes a map that contains the pathnam...
static ArrayList< DGraph > readDENOPTIMGraphsFromTxtFile(String fileName, FragmentSpace fragSpace, Logger logger)
Reads a list of <DGraphs from a text file.
static ArrayList< IAtomContainer > readSDFFile(String fileName)
Reads a file containing multiple molecules (multiple SD format))
static void writeGraphsToSDF(File file, List< DGraph > graphs, Logger logger, Randomizer randomizer)
Writes the graphs to SDF file.
static void readCuttingRules(BufferedReader reader, List< CuttingRule > cutRules, String source)
Read cutting rules from a stream.
static void writeCandidateToFile(File file, Candidate candidate, boolean append)
Writes one candidate item to file.
static void writeGraphToSDF(File file, DGraph graph, boolean append, boolean make3D, Logger logger, Randomizer randomizer)
Writes the graph to SDF file.
static void writeCuttingRules(File file, List< CuttingRule > cutRules)
Writes a formatted text file that collects cutting rule.
static void writeSDFFile(String fileName, List< IAtomContainer > mols, boolean append)
Writes a set of IAtomContainers to SDF file.
static void writeGraphsToSDF(File file, List< DGraph > modGraphs, boolean append, boolean make3D, Logger logger, Randomizer randomizer)
Writes the graphs to SDF file.
static Object readDENOPTIMData(String pathname)
Reads any content of a given pathname and tries to read DENOPTIM data from it.
static File writeVertexToFile(File file, FileFormat format, Vertex vertex, boolean append)
Writes vertexes to file.
static void readCompatibilityMatrix(String fileName, HashMap< APClass, ArrayList< APClass > > compatMap, HashMap< APClass, APClass > cappingMap, Set< APClass > forbiddenEndList)
Read the APclass compatibility matrix data from file.
static void writeSmilesSet(String fileName, String[] smiles, boolean append)
Writes multiple smiles string array to the specified file.
static void writeVertexesToJSON(File file, List< Vertex > vertexes, boolean append)
Writes vertexes to JSON file.
static double[] readPopulationProps(File file)
Read the min, max, mean, and median of a population from FileFormat#GENSUMMARY file.
static Set< APClass > readAllAPClasses(File fragLib)
static ArrayList< DGraph > readDENOPTIMGraphsFromJSONFile(String fileName)
Reads a list of DGraphs from a JSON file.
static ArrayList< String > readList(String fileName, boolean allowEmpty)
Read list of data as text.
static File writeGraphsToFile(File file, FileFormat format, List< DGraph > modGraphs, Logger logger, Randomizer randomizer)
Writes the graphs to file.
static List< BridgeHeadFindingRule > readBridgeHesFindingRules(BufferedReader br)
Reads a list of rules for identifying potential bridge-head sites.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of DGraphs from file.
static final String NL
Newline character from system.
static List< CandidateLW > readLightWeightCandidate(File file)
Read only selected data from a GA produced items.
static void writeGraphsToJSON(File file, List< DGraph > graphs, boolean append)
Writes the graphs to JSON file.
static List< Map< String, Object > > readSDFProperties(String pathName, List< String > propNames)
Extract selected properties from SDF files.
static void writeGraphToJSON(File file, DGraph graph)
Writes the graph to JSON file.
static void writeSmiles(String fileName, String smiles, boolean append)
Writes a single smiles string to the specified file.
static String readText(String fileName)
Read text from file.
static void writeGraphsToSDF(File file, List< DGraph > graphs, boolean append, Logger logger, Randomizer randomizer)
Writes the graphs to SDF file.
static void writeVertexToSDF(String pathName, Vertex vertex)
Writes a vertex to an SDF file.
static ArrayList< DGraph > readDENOPTIMGraphsFromSDFile(String fileName)
Reads a list of <DGraphs from a SDF file.
static void writeVertexesToJSON(File file, List< Vertex > vertexes)
Writes vertexes to JSON file.
static void writeMol2File(String fileName, IAtomContainer mol, boolean append)
static List< BridgeHeadFindingRule > readBridgeHesFindingRules(String fileName)
Reads a list of rules for identifying potential bridge-head sites.
static ArrayList< String > readList(String fileName)
Read list of data as text.
static void appendTxtFiles(File f1, List< File > files)
Appends the second file to the first.
static DGraph readGraphFromSDFileIAC(IAtomContainer mol, int molId)
Converts an atom container read in from an SDF file into a graph, if possible.
static ArrayList< Vertex > readVertexes(File file, Vertex.BBType bbt)
Reads Vertexes from any file that can contain such items.
static void writeData(String fileName, String data, boolean append)
Write text-like data file.
static void writeGraphsToJSON(File file, List< DGraph > graphs)
Writes the graphs to JSON file.
static List< IAtomContainer > readAllAtomContainers(File file)
Returns a single collection with all atom containers found in a file of any format.
static List< CandidateLW > readPopulationMembersTraces(File file)
Read the minimal info that can be found in a FileFormat#GENSUMMARY file about the members of a popula...
static void writeCandidatesToFile(File file, List< Candidate > popMembers, boolean append)
Writes candidate items to file.
static void writeCompatibilityMatrix(String fileName, HashMap< APClass, ArrayList< APClass > > cpMap, HashMap< APClass, APClass > capMap, HashSet< APClass > ends)
The class compatibility matrix.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes, boolean append)
Writes vertexes to file.
static final String FS
File separator from system.
static String getChemDoodleString(IAtomContainer mol)
Generate the ChemDoodle representation of the molecule.
static ArrayList< GraphEdit > readDENOPTIMGraphEditFromFile(String fileName)
Reads a list of graph editing tasks from a JSON file.
static void writeVertexesToSDF(File file, List< Vertex > vertexes, boolean append)
Write a list of vertexes to file.
static ArrayList< Vertex > readDENOPTIMVertexesFromSDFile(String fileName, Vertex.BBType bbt)
Reads a list of Vertexes from a SDF file.
static ArrayList< Candidate > readCandidates(File file, boolean allowNoUID)
Reads SDF files that represent one or more tested or to be tested candidates.
Class for de/serializing DENOPTIM graphs from/to JSON format.
Logger class for DENOPTIM.
static final Logger appLogger
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
A cutting rule with three SMARTS queries (atom 1, bond, atom2) and options.
Definition of a graph editing task.
static void writeSDFFields(IAtomContainer iac, DGraph g)
Tool to generate random numbers and random decisions.
The type of building block.