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.fragspace.FragmentSpace;
87import denoptim.graph.APClass;
88import denoptim.graph.AttachmentPoint;
89import denoptim.graph.Candidate;
90import denoptim.graph.CandidateLW;
91import denoptim.graph.DGraph;
92import denoptim.graph.Template;
93import denoptim.graph.Vertex;
94import denoptim.graph.Vertex.BBType;
95import denoptim.json.DENOPTIMgson;
96import denoptim.logging.StaticLogger;
97import denoptim.molecularmodeling.ThreeDimTreeBuilder;
98import denoptim.programs.fragmenter.CuttingRule;
99import denoptim.utils.GraphConversionTool;
100import denoptim.utils.GraphEdit;
101import denoptim.utils.GraphUtils;
102import denoptim.utils.Randomizer;
118 public static final String
FS = System.getProperty(
"file.separator");
123 public static final String
NL = System.getProperty(
"line.separator");
125 private static final IChemObjectBuilder
builder =
126 SilentChemObjectBuilder.getInstance();
143 File file =
new File(pathname);
189 data = graphs.get(0);
200 data = graphs.get(0);
216 + format +
"' cannot be loaded yet. Please, contact"
217 +
"the development team.");
240 ArrayList<Candidate> cands =
new ArrayList<Candidate>();
242 String genSummaryParentDir = file.getParent();
243 for (String candPathname : pathnames)
245 File candFile =
new File(candPathname);
246 if (candFile.exists())
249 }
else if (genSummaryParentDir!=
null) {
252 String runFolderPathname =
253 candFile.getParentFile()
255 if (runFolderPathname==
null)
257 +
"folder for '"+ genSummaryParentDir +
"'");
259 String genAndMolPath = candFile.getAbsolutePath()
260 .substring(runFolderPathname.length());
263 genSummaryParentDir+genAndMolPath)).
get(0));
283 throws IOException, CDKException
285 List<IAtomContainer> results =
null;
287 FileReader formatReader =
new FileReader(file);
288 IChemFormat chemFormat =
new FormatFactory().guessFormat(
289 new BufferedReader(formatReader));
290 formatReader.close();
292 if (chemFormat instanceof CIFFormat)
313 Map<String, Object> info =
new Hashtable<String, Object>();
314 info.put(
"adapter",
new SmarterJmolAdapter());
315 info.put(
"isApp",
false);
316 info.put(
"silent",
"");
317 Viewer v =
new Viewer(info);
318 v.loadModelFromFile(
null, file.getAbsolutePath(),
null,
null,
319 false,
null,
null,
null, 0,
" ");
321 v.scriptWait(
"write " + tmp +
" as sdf");
326 FileReader fileReader =
new FileReader(file);
327 ReaderFactory readerFact =
new ReaderFactory();
328 ISimpleChemObjectReader reader = readerFact.createReader(fileReader);
329 IChemFile chemFile = (IChemFile) reader.read(
330 (IChemObject)
new ChemFile());
331 results = ChemFileManipulator.getAllAtomContainers(chemFile);
347 public static ArrayList<IAtomContainer>
readSDFFile(String fileName)
349 MDLV2000Reader mdlreader =
null;
350 ArrayList<IAtomContainer> lstContainers =
new ArrayList<>();
353 mdlreader =
new MDLV2000Reader(
new FileReader(
new File(fileName)));
354 ChemFile chemFile = (ChemFile) mdlreader.read((ChemObject)
new ChemFile());
355 lstContainers.addAll(
356 ChemFileManipulator.getAllAtomContainers(chemFile));
357 }
catch (CDKException | IOException cdke) {
361 if (mdlreader !=
null) {
364 }
catch (IOException ioe) {
369 if (lstContainers.isEmpty()) {
373 return lstContainers;
405 ArrayList<Vertex> lst =
new ArrayList<Vertex>();
423 if (FilenameUtils.getExtension(file.getName()).equals(
""))
425 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
477 file.getAbsolutePath());
478 allVertexes.addAll(vertexes);
479 writeData(file.getAbsolutePath(), writer.toJson(allVertexes),
false);
481 writeData(file.getAbsolutePath(), writer.toJson(vertexes),
false);
498 List<Vertex> lst =
new ArrayList<Vertex>();
514 List<Vertex> vertexes,
boolean append)
517 List<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
520 lst.add(v.getIAtomContainer());
536 List<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
550 public static void writeSDFFile(String fileName, List<IAtomContainer> mols)
565 public static void writeSDFFile(String fileName, List<IAtomContainer> mols,
568 SDFWriter sdfWriter =
null;
570 IAtomContainerSet molSet =
new AtomContainerSet();
571 for (
int idx = 0; idx < mols.size(); idx++) {
572 molSet.addAtomContainer(mols.get(idx));
574 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName),append));
575 sdfWriter.write(molSet);
576 }
catch (CDKException | IOException cdke) {
580 if (sdfWriter !=
null) {
583 }
catch (IOException ioe) {
601 SDFWriter sdfWriter =
null;
603 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName), append));
604 sdfWriter.write(mol);
605 }
catch (CDKException | IOException cdke) {
609 if (sdfWriter !=
null) {
612 }
catch (IOException ioe) {
622 Mol2Writer mol2Writer =
null;
624 mol2Writer =
new Mol2Writer(
new FileWriter(
new File(fileName), append));
625 mol2Writer.write(mol);
626 }
catch (CDKException cdke) {
628 }
catch (IOException ioe) {
632 if (mol2Writer !=
null) {
635 }
catch (IOException ioe) {
645 XYZWriter xyzWriter =
null;
647 xyzWriter =
new XYZWriter(
new FileWriter(
new File(fileName), append));
648 xyzWriter.write(mol);
649 }
catch (CDKException cdke) {
651 }
catch (IOException ioe) {
655 if (xyzWriter !=
null) {
658 }
catch (IOException ioe) {
677 FileWriter fw =
null;
679 fw =
new FileWriter(
new File(fileName), append);
680 for (
int i = 0; i < smiles.length; i++) {
681 fw.write(smiles[i] +
NL);
684 }
catch (IOException ioe) {
691 }
catch (IOException ioe) {
710 FileWriter fw =
null;
712 fw =
new FileWriter(
new File(fileName), append);
713 fw.write(smiles +
NL);
715 }
catch (IOException ioe) {
722 }
catch (IOException ioe) {
738 public static void writeData(String fileName, String data,
boolean append)
740 FileWriter fw =
null;
742 fw =
new FileWriter(
new File(fileName), append);
745 }
catch (IOException ioe) {
752 }
catch (IOException ioe) {
772 List<String> propNames =
new ArrayList<String>(Arrays.asList(
776 List<String> optionalPropNames =
new ArrayList<String>(Arrays.asList(
782 propNames.addAll(optionalPropNames);
784 file.getAbsolutePath(), propNames);
786 List<CandidateLW> items =
new ArrayList<CandidateLW>();
787 for (Map<String, Object> props : propsPerItem)
795 Object nameObj = props.get(CDKConstants.TITLE);
799 + CDKConstants.TITLE +
" is null!");
802 nameObj.toString(),file.getAbsolutePath());
804 for (String propName : optionalPropNames)
806 Object obj = props.get(propName);
812 item.
setFitness(Double.parseDouble(obj.toString()));
824 item.
setLevel(Integer.parseInt(obj.toString()));
846 double[] vals =
new double[4];
847 ArrayList<String> txt =
readList(file.getAbsolutePath());
848 for (String line : txt) {
849 if (line.trim().length() < 8) {
853 String key = line.toUpperCase().trim().substring(0, 8);
856 vals[0] = Double.parseDouble(line.split(
"\\s+")[1]);
860 vals[1] = Double.parseDouble(line.split(
"\\s+")[1]);
864 vals[2] = Double.parseDouble(line.split(
"\\s+")[1]);
868 vals[3] = Double.parseDouble(line.split(
"\\s+")[1]);
888 List<String> vals =
new ArrayList<String>();
889 ArrayList<String> txt =
readList(file.getAbsolutePath());
890 for (String line : txt)
892 if (!line.contains(
FS))
895 String[] words = line.trim().split(
"\\s+");
896 if (words.length < 5)
921 List<CandidateLW> members =
new ArrayList<CandidateLW>();
922 List<String> txt =
readList(file.getAbsolutePath());
925 for (
int i=1; i<txt.size(); i++)
927 String line = txt.get(i);
932 if (line.startsWith(
"#"))
938 String[] words = line.trim().split(
"\\s+");
939 String pathname =
"nofile";
940 if (words.length >= 5)
945 member.
setFitness(Double.parseDouble(words[3]));
960 public static ArrayList<String>
readList(String fileName)
976 public static ArrayList<String>
readList(String fileName,
978 ArrayList<String> lst =
new ArrayList<>();
979 BufferedReader br =
null;
982 br =
new BufferedReader(
new FileReader(fileName));
983 while ((line = br.readLine()) !=
null) {
984 if (line.trim().length() == 0) {
987 lst.add(line.trim());
989 }
catch (IOException ioe) {
996 }
catch (IOException ioe) {
1001 if (lst.isEmpty() && !allowEmpty) {
1018 StringBuilder sb =
new StringBuilder();
1019 BufferedReader br =
null;
1022 br =
new BufferedReader(
new FileReader(fileName));
1023 while ((line = br.readLine()) !=
null) {
1024 sb.append(line).append(
NL);
1026 }
catch (IOException ioe) {
1033 }
catch (IOException ioe) {
1038 return sb.toString();
1054 List<Map<String,Object>> results =
new ArrayList<Map<String,Object>>();
1056 for (IAtomContainer iac : iacs)
1058 Map<String,Object> properties =
new HashMap<String,Object>();
1059 for (String propName : propNames)
1061 properties.put(propName, iac.getProperty(propName));
1063 results.add(properties);
1079 StringWriter stringWriter =
new StringWriter();
1080 MDLV2000Writer mw =
null;
1082 mw =
new MDLV2000Writer(stringWriter);
1084 }
catch (CDKException cdke) {
1091 }
catch (IOException ioe) {
1096 String MoleculeString = stringWriter.toString();
1100 String Moleculelines[] = MoleculeString.split(
"\\r?\\n");
1102 StringBuilder sb =
new StringBuilder(1024);
1103 sb.append(
"var molFile = '");
1104 for (
int i = 0; i < Moleculelines.length; i++) {
1105 sb.append(Moleculelines[i]);
1109 return sb.toString();
1115 Set<APClass> allCLasses =
new HashSet<APClass>();
1120 allCLasses.add(ap.getAPClass());
1125 System.out.println(
"Could not read data from '" + fragLib +
"'. "
1126 +
"Cause: " + e.getMessage());
1143 HashMap<
APClass, ArrayList<APClass>> cpMap,
1144 HashMap<APClass, APClass> capMap,
1146 DateFormat dateFormat =
new SimpleDateFormat(
"dd/MM/yy HH:mm:ss");
1147 Date date =
new Date();
1148 String dateStr = dateFormat.format(date);
1150 StringBuilder sb =
new StringBuilder();
1152 sb.append(
" Compatibility matrix data").append(
NL);
1154 sb.append(
" Written by DENOPTIM-GUI on ").append(dateStr).append(
NL);
1156 sb.append(
" APCLass Compatibility rules").append(
NL);
1157 SortedSet<APClass> keysCPMap =
new TreeSet<APClass>();
1158 keysCPMap.addAll(cpMap.keySet());
1159 for (
APClass srcAPC : keysCPMap) {
1161 sb.append(srcAPC).append(
" ");
1162 for (
int i = 0; i < cpMap.get(srcAPC).size(); i++) {
1163 APClass trgAPC = cpMap.get(srcAPC).get(i);
1165 if (i != (cpMap.get(srcAPC).size() - 1)) {
1174 sb.append(
" Capping rules").append(
NL);
1175 SortedSet<APClass> keysCap =
new TreeSet<APClass>();
1176 keysCap.addAll(capMap.keySet());
1179 sb.append(apc).append(
" ").append(capMap.get(apc)).append(
NL);
1183 sb.append(
" Forbidden ends").append(
NL);
1184 SortedSet<APClass> sortedFE =
new TreeSet<APClass>();
1185 sortedFE.addAll(ends);
1186 for (
APClass apc : sortedFE) {
1188 sb.append(apc).append(
" ").append(
NL);
1206 ArrayList<APClass>> compatMap,
1207 HashMap<APClass, APClass> cappingMap, Set<APClass> forbiddenEndList)
1210 BufferedReader br =
null;
1213 br =
new BufferedReader(
new FileReader(fileName));
1214 while ((line = br.readLine()) !=
null) {
1215 if (line.trim().length() == 0) {
1224 String str[] = line.split(
"\\s+");
1225 if (str.length < 3) {
1226 String err =
"Incomplete APClass compatibility line '"
1232 ArrayList<APClass> trgAPCs =
new ArrayList<APClass>();
1233 for (String s : str[2].split(
","))
1237 compatMap.put(srcAPC, trgAPCs);
1240 String str[] = line.split(
"\\s+");
1241 if (str.length != 3) {
1242 String err =
"Incomplete capping line '"
1248 cappingMap.put(srcAPC, trgAPC);
1250 if (line.startsWith(
1252 String str[] = line.split(
"\\s+");
1253 if (str.length != 2) {
1254 for (
int is = 1; is < str.length; is++) {
1255 forbiddenEndList.add(
1265 }
catch (NumberFormatException | IOException nfe) {
1272 }
catch (IOException ioe) {
1277 if (compatMap.isEmpty()) {
1278 String err =
"No reaction compatibility data found in file: ";
1300 HashMap<
APClass, ArrayList<APClass>> rcCompatMap)
1302 BufferedReader br =
null;
1305 br =
new BufferedReader(
new FileReader(fileName));
1306 while ((line = br.readLine()) !=
null) {
1307 if (line.trim().length() == 0) {
1316 String str[] = line.split(
"\\s+");
1317 if (str.length < 3) {
1318 String err =
"Incomplete reaction compatibility data.";
1324 String strRcn[] = str[2].split(
",");
1325 for (
int i = 0; i < strRcn.length; i++) {
1326 strRcn[i] = strRcn[i].trim();
1329 if (rcCompatMap.containsKey(srcAPC)) {
1330 rcCompatMap.get(srcAPC).add(trgAPC);
1332 ArrayList<APClass> list =
new ArrayList<APClass>();
1334 rcCompatMap.put(srcAPC, list);
1337 if (rcCompatMap.containsKey(trgAPC)) {
1338 rcCompatMap.get(trgAPC).add(srcAPC);
1340 ArrayList<APClass> list =
new ArrayList<APClass>();
1342 rcCompatMap.put(trgAPC, list);
1347 }
catch (NumberFormatException | IOException nfe) {
1354 }
catch (IOException ioe) {
1359 if (rcCompatMap.isEmpty()) {
1360 String err =
"No reaction compatibility data found in file: ";
1399 String filename = file.getAbsolutePath();
1400 ArrayList<Candidate> candidates =
new ArrayList<>();
1401 ArrayList<IAtomContainer> iacs =
readSDFFile(file.getAbsolutePath());
1405 if (file.getParentFile()!=
null
1406 && file.getParentFile().getName().startsWith(
1409 String genFolderName = file.getParentFile().getName();
1410 genID = Integer.valueOf(genFolderName.substring(
1414 for (IAtomContainer iac : iacs) {
1419 candidates.add(cand);
1434 List<Candidate> popMembers,
boolean append)
1437 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1439 file =
new File(file.getAbsoluteFile() +
"."
1442 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
1445 lst.add(g.getFitnessProviderOutputRepresentation());
1463 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1465 file =
new File(file.getAbsoluteFile() +
"."
1469 candidate.getFitnessProviderOutputRepresentation(), append);
1484 ArrayList<GraphEdit> graphEditTasks =
new ArrayList<>();
1487 BufferedReader br =
null;
1490 br =
new BufferedReader(
new FileReader(fileName));
1491 graphEditTasks = reader.fromJson(br,
1492 new TypeToken<ArrayList<GraphEdit>>(){}.getType());
1494 catch (FileNotFoundException fnfe)
1498 catch (JsonSyntaxException jse)
1500 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1501 if (jse.getMessage().contains(msg))
1508 br =
new BufferedReader(
new FileReader(fileName));
1510 catch (FileNotFoundException fnfe)
1513 }
catch (IOException ioe)
1517 GraphEdit graphEditTask = reader.fromJson(br,
1519 graphEditTasks.add(graphEditTask);
1521 jse.printStackTrace();
1523 +
"that defines a graph enditing task.",jse);
1533 }
catch (IOException ioe) {
1538 return graphEditTasks;
1578 inFile.getAbsolutePath());
1582 inFile.getAbsolutePath());
1587 +
"JSON format instead.");
1591 inFile.getAbsolutePath());
1594 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
1597 for (
Vertex v : vertexes)
1601 graphs.add(((
Template)v).getInnerGraph());
1604 System.out.println(
"WARNING: Reading graphs from "
1606 +
"templates' inner graphs. Importing "
1607 + graphs.size() +
" graphs "
1608 +
"from " + vertexes.size() +
" vertexes.");
1612 throw new Exception(
"Format '" + format +
"' could not be used "
1613 +
"to read graphs from file '" + inFile +
"'.");
1629 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1632 for (IAtomContainer mol : mols)
1702 +
"files containing graphs must include the "
1705 String msg =
"Attempt to load graph form "
1706 +
"SDF that has no '" + DENOPTIMConstants.GRAPHJSONTAG
1710 msg = msg +
" Check molecule " + molId;
1711 if (!fileName.isEmpty())
1713 msg = msg +
" in the SDF file '" + fileName +
"'";
1720 String js = json.toString();
1724 }
catch (Exception e)
1726 String msg = e.getMessage();
1729 msg = msg +
" Check molecule " + molId;
1730 if (!fileName.isEmpty())
1732 msg = msg +
" in the SDF file '" + fileName +
"'";
1756 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1757 BufferedReader br =
null;
1760 br =
new BufferedReader(
new FileReader(fileName));
1761 while ((line = br.readLine()) !=
null) {
1762 if (line.trim().length() == 0) {
1774 }
catch (Throwable t) {
1775 String msg =
"Cannot convert string to DENOPTIMGraph. "
1776 +
"Check line '" + line.trim() +
"'";
1777 logger.log(Level.SEVERE, msg);
1782 }
catch (IOException ioe) {
1783 String msg =
"Cannot read file " + fileName;
1784 logger.log(Level.SEVERE, msg);
1791 }
catch (IOException ioe) {
1812 ArrayList<Vertex> result =
new ArrayList<Vertex>();
1815 BufferedReader br =
null;
1818 br =
new BufferedReader(
new FileReader(fileName));
1819 result = reader.fromJson(br,
1820 new TypeToken<ArrayList<Vertex>>(){}.getType());
1822 catch (FileNotFoundException fnfe)
1826 catch (JsonSyntaxException jse)
1828 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1829 if (jse.getMessage().contains(msg))
1836 br =
new BufferedReader(
new FileReader(fileName));
1838 catch (FileNotFoundException fnfe)
1841 }
catch (IOException ioe)
1849 + fileName +
"'.", jse);
1859 }
catch (IOException ioe) {
1878 ArrayList<DGraph> list_of_graphs =
new ArrayList<DGraph>();
1881 BufferedReader br =
null;
1884 br =
new BufferedReader(
new FileReader(fileName));
1885 list_of_graphs = reader.fromJson(br,
1886 new TypeToken<ArrayList<DGraph>>(){}.getType());
1888 catch (FileNotFoundException fnfe)
1892 catch (JsonSyntaxException jse)
1894 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1895 if (jse.getMessage().contains(msg))
1902 br =
new BufferedReader(
new FileReader(fileName));
1904 catch (FileNotFoundException fnfe)
1907 }
catch (IOException ioe)
1912 list_of_graphs.add(g);
1915 +
"JSON '" + fileName +
"'", jse);
1925 }
catch (IOException ioe) {
1930 return list_of_graphs;
1947 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1949 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
1980 List<DGraph> modGraphs, Logger logger,
Randomizer randomizer)
1983 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1985 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2014 List<DGraph> graphs, Logger logger,
Randomizer randomizer)
2032 boolean append,
boolean make3D, Logger logger,
Randomizer randomizer)
2035 List<DGraph> lst =
new ArrayList<>(1);
2051 boolean append, Logger logger,
Randomizer randomizer)
2054 ArrayList<DGraph> lst =
new ArrayList<>(1);
2070 List<DGraph> graphs,
boolean append,
2089 List<DGraph> modGraphs,
boolean append,
boolean make3D,
2092 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
2093 for (
DGraph g : modGraphs)
2096 IAtomContainer iac =
builder.newAtomContainer();
2101 }
catch (Throwable t) {
2102 t.printStackTrace();
2103 logger.log(Level.WARNING,
"Couldn't make 3D-tree "
2104 +
"representation: " + t.getMessage());
2126 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
2144 writeData(file.getAbsolutePath(), writer.toJson(modGraphs),
false);
2161 writeData(file.getAbsolutePath(), writer.toJson(graphs), append);
2177 writeData(fileName, graph.toString(), append);
2191 Map<File, FileFormat> map =
new LinkedHashMap<File, FileFormat>();
2202 String[] parts = line.split(
"\\s+");
2203 String ffStr = parts[0];
2208 }
catch (Exception e)
2211 +
"' to a known file format.");
2213 String fileName = line.substring(ffStr.length()).trim();
2216 map.put(
new File(fileName), ff);
2222 +
"fetch list of recent files.", e);
2223 map =
new HashMap<File, FileFormat>();
2247 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2253 file.getAbsolutePath(),bbt);
2258 file.getAbsolutePath());
2262 ArrayList<DGraph> lstGraphs =
2264 for (
DGraph g : lstGraphs)
2273 ArrayList<DGraph> lstGraphs2 =
2275 for (
DGraph g : lstGraphs2)
2285 +
"' could not be used to "
2286 +
"read in vertices from file '" + file +
"'.");
2303 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2316 +
" in file " + fileName,e);
2344 LinkedHashMap<String, String> allFormulae =
new LinkedHashMap<String,String>();
2345 BufferedReader buffRead =
null;
2348 buffRead =
new BufferedReader(
new FileReader(file));
2349 String lineAll =
null;
2350 String refcode =
"";
2351 String formula =
"";
2352 while ((lineAll = buffRead.readLine()) !=
null)
2354 String[] lineArgs = lineAll.split(
":");
2356 if (lineArgs[0].equals(
"REFCODE"))
2357 refcode = lineArgs[1].trim();
2360 if (lineArgs[0].equals(
" Formula"))
2362 formula = lineArgs[1].trim();
2364 allFormulae.put(refcode,formula);
2370 }
catch (FileNotFoundException fnf) {
2372 }
catch (IOException ioex) {
2376 if (buffRead !=
null)
2378 }
catch (IOException e) {
2402 ArrayList<String> cutRulLines =
new ArrayList<String>();
2406 while ((line = reader.readLine()) !=
null)
2409 cutRulLines.add(line.trim());
2411 }
catch (IOException e)
2419 }
catch (IOException e)
2440 ArrayList<String> allLines =
readList(file.getAbsolutePath());
2443 ArrayList<String> cutRulLines =
new ArrayList<String>();
2445 .filter(line -> line.trim().startsWith(
2447 .forEach(line -> cutRulLines.add(line.trim()));
2450 + file.getAbsolutePath()+
"'");
2471 Set<Integer> usedPriorities =
new HashSet<Integer>();
2472 for (
int i = 0; i<cutRulLines.size(); i++)
2474 String[] words = cutRulLines.get(i).split(
"\\s+");
2475 String name = words[1];
2476 if (words.length < 6)
2479 +
" Found " + words.length +
" parts inctead of 6."
2480 +
"Check line '" + cutRulLines.get(i) +
"'"
2481 +
"in " + source +
".");
2485 ArrayList<String> opts =
new ArrayList<String>();
2486 if (words.length >= 7)
2488 for (
int wi=6; wi<words.length; wi++)
2490 opts.add(words[wi]);
2494 int priority = Integer.parseInt(words[2]);
2495 if (usedPriorities.contains(priority))
2498 +
" Duplicate priority index " + priority +
". "
2499 +
"Check line '" + cutRulLines.get(i) +
"'"
2500 +
"in " + source +
".");
2502 usedPriorities.add(priority);
2515 Collections.sort(cutRules,
new Comparator<CuttingRule>() {
2537 StringBuilder sb =
new StringBuilder();
2541 sb.append(r.getName()).append(
" ");
2542 sb.append(r.getPriority()).append(
" ");
2543 sb.append(r.getSMARTSAtom0()).append(
" ");
2544 sb.append(r.getSMARTSAtom1()).append(
" ");
2545 sb.append(r.getSMARTSBnd()).append(
" ");
2546 if (r.getOptions()!=
null)
2548 for (String opt : r.getOptions())
2549 sb.append(opt).append(
" ");
2553 writeData(file.getAbsolutePath(), sb.toString(),
false);
2568 PrintWriter pw =
null;
2571 fw =
new FileWriter(f1,
true);
2572 bw =
new BufferedWriter(fw);
2573 pw =
new PrintWriter(bw);
2574 for (File inFile : files)
2577 BufferedReader br =
null;
2580 fr =
new FileReader(inFile);
2581 br =
new BufferedReader(fr);
2583 while ((line = br.readLine()) !=
null)
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 void writeGraphsToJSON(File file, List< DGraph > modGraphs)
Writes the graphs to JSON 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 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 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 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.