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.DefaultChemObjectReader;
65import org.openscience.cdk.io.FormatFactory;
66import org.openscience.cdk.io.IChemObjectReaderErrorHandler;
67import org.openscience.cdk.io.ISimpleChemObjectReader;
68import org.openscience.cdk.io.MDLV2000Reader;
69import org.openscience.cdk.io.MDLV2000Writer;
70import org.openscience.cdk.io.Mol2Writer;
71import org.openscience.cdk.io.ReaderFactory;
72import org.openscience.cdk.io.SDFWriter;
73import org.openscience.cdk.io.XYZWriter;
74import org.openscience.cdk.io.formats.CIFFormat;
75import org.openscience.cdk.io.formats.IChemFormat;
76import org.openscience.cdk.silent.SilentChemObjectBuilder;
77import org.openscience.cdk.tools.ILoggingTool;
78import org.openscience.cdk.tools.LoggingToolFactory;
79import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
81import com.google.gson.Gson;
82import com.google.gson.JsonSyntaxException;
83import com.google.gson.reflect.TypeToken;
85import denoptim.constants.DENOPTIMConstants;
86import denoptim.exception.DENOPTIMException;
87import denoptim.files.FileFormat;
88import denoptim.files.FileUtils;
89import denoptim.files.UndetectedFileFormatException;
90import denoptim.fragmenter.BridgeHeadFindingRule;
91import denoptim.fragspace.FragmentSpace;
92import denoptim.graph.APClass;
93import denoptim.graph.AttachmentPoint;
94import denoptim.graph.Candidate;
95import denoptim.graph.CandidateLW;
96import denoptim.graph.DGraph;
97import denoptim.graph.Template;
98import denoptim.graph.Vertex;
99import denoptim.graph.Vertex.BBType;
100import denoptim.json.DENOPTIMgson;
101import denoptim.logging.StaticLogger;
102import denoptim.molecularmodeling.ThreeDimTreeBuilder;
103import denoptim.programs.fragmenter.CuttingRule;
104import denoptim.utils.GraphConversionTool;
105import denoptim.utils.GraphEdit;
106import denoptim.utils.GraphUtils;
107import denoptim.utils.Randomizer;
123 public static final String
FS = System.getProperty(
"file.separator");
128 public static final String
NL = System.getProperty(
"line.separator");
130 private static final IChemObjectBuilder
builder =
131 SilentChemObjectBuilder.getInstance();
148 File file =
new File(pathname);
194 data = graphs.get(0);
205 data = graphs.get(0);
221 + format +
"' cannot be loaded yet. Please, contact"
222 +
"the development team.");
245 ArrayList<Candidate> cands =
new ArrayList<Candidate>();
247 String genSummaryParentDir = file.getParent();
248 for (String candPathname : pathnames)
250 File candFile =
new File(candPathname);
251 if (candFile.exists())
254 }
else if (genSummaryParentDir!=
null) {
257 String runFolderPathname =
258 candFile.getParentFile()
260 if (runFolderPathname==
null)
262 +
"folder for '"+ genSummaryParentDir +
"'");
264 String genAndMolPath = candFile.getAbsolutePath()
265 .substring(runFolderPathname.length());
268 genSummaryParentDir+genAndMolPath)).
get(0));
288 throws IOException, CDKException
290 List<IAtomContainer> results =
null;
292 FileReader formatReader =
new FileReader(file);
293 IChemFormat chemFormat =
new FormatFactory().guessFormat(
294 new BufferedReader(formatReader));
295 formatReader.close();
297 if (chemFormat instanceof CIFFormat)
318 Map<String, Object> info =
new Hashtable<String, Object>();
319 info.put(
"adapter",
new SmarterJmolAdapter());
320 info.put(
"isApp",
false);
321 info.put(
"silent",
"");
322 Viewer v =
new Viewer(info);
323 v.loadModelFromFile(
null, file.getAbsolutePath(),
null,
null,
324 false,
null,
null,
null, 0,
" ");
326 v.scriptWait(
"write " + tmp +
" as sdf");
331 FileReader fileReader =
new FileReader(file);
332 ReaderFactory readerFact =
new ReaderFactory();
333 ISimpleChemObjectReader reader = readerFact.createReader(fileReader);
335 DefaultChemObjectReader.class));
336 IChemFile chemFile = (IChemFile) reader.read(
337 (IChemObject)
new ChemFile());
338 results = ChemFileManipulator.getAllAtomContainers(chemFile);
354 public static ArrayList<IAtomContainer>
readSDFFile(String fileName)
356 MDLV2000Reader mdlreader =
null;
357 ArrayList<IAtomContainer> lstContainers =
new ArrayList<>();
360 mdlreader =
new MDLV2000Reader(
new FileReader(
new File(fileName)));
362 DefaultChemObjectReader.class));
363 ChemFile chemFile = (ChemFile) mdlreader.read((ChemObject)
new ChemFile());
364 lstContainers.addAll(
365 ChemFileManipulator.getAllAtomContainers(chemFile));
366 }
catch (CDKException | IOException cdke) {
370 if (mdlreader !=
null) {
373 }
catch (IOException ioe) {
378 if (lstContainers.isEmpty()) {
382 return lstContainers;
404 this(LoggingToolFactory.createLoggingTool(clazz));
427 public void handleError(String message,
int row,
int colStart,
int colEnd) {
432 public void handleError(String message,
int row,
int colStart,
int colEnd, Exception exception) {
443 logger.fatal(message +
", " + exception);
448 logger.fatal(message +
", row " + row +
" column " + colStart +
"-" + colEnd);
452 public void handleFatalError(String message,
int row,
int colStart,
int colEnd, Exception exception) {
453 logger.fatal(message +
", row " + row +
" column " + colStart +
"-" + colEnd +
", " + exception);
458 return message.contains(
"invalid symbol:");
491 ArrayList<Vertex> lst =
new ArrayList<Vertex>();
509 if (FilenameUtils.getExtension(file.getName()).equals(
""))
511 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
563 file.getAbsolutePath());
564 allVertexes.addAll(vertexes);
565 writeData(file.getAbsolutePath(), writer.toJson(allVertexes),
false);
567 writeData(file.getAbsolutePath(), writer.toJson(vertexes),
false);
584 List<Vertex> lst =
new ArrayList<Vertex>();
600 List<Vertex> vertexes,
boolean append)
603 List<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
606 lst.add(v.getIAtomContainer());
622 List<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
636 public static void writeSDFFile(String fileName, List<IAtomContainer> mols)
651 public static void writeSDFFile(String fileName, List<IAtomContainer> mols,
654 SDFWriter sdfWriter =
null;
656 IAtomContainerSet molSet =
new AtomContainerSet();
657 for (
int idx = 0; idx < mols.size(); idx++) {
658 molSet.addAtomContainer(mols.get(idx));
660 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName),append));
661 sdfWriter.write(molSet);
662 }
catch (CDKException | IOException cdke) {
666 if (sdfWriter !=
null) {
669 }
catch (IOException ioe) {
687 SDFWriter sdfWriter =
null;
689 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName), append));
690 sdfWriter.write(mol);
691 }
catch (CDKException | IOException cdke) {
695 if (sdfWriter !=
null) {
698 }
catch (IOException ioe) {
708 Mol2Writer mol2Writer =
null;
710 mol2Writer =
new Mol2Writer(
new FileWriter(
new File(fileName), append));
711 mol2Writer.write(mol);
712 }
catch (CDKException cdke) {
714 }
catch (IOException ioe) {
718 if (mol2Writer !=
null) {
721 }
catch (IOException ioe) {
731 XYZWriter xyzWriter =
null;
733 xyzWriter =
new XYZWriter(
new FileWriter(
new File(fileName), append));
734 xyzWriter.write(mol);
735 }
catch (CDKException cdke) {
737 }
catch (IOException ioe) {
741 if (xyzWriter !=
null) {
744 }
catch (IOException ioe) {
763 FileWriter fw =
null;
765 fw =
new FileWriter(
new File(fileName), append);
766 for (
int i = 0; i < smiles.length; i++) {
767 fw.write(smiles[i] +
NL);
770 }
catch (IOException ioe) {
777 }
catch (IOException ioe) {
796 FileWriter fw =
null;
798 fw =
new FileWriter(
new File(fileName), append);
799 fw.write(smiles +
NL);
801 }
catch (IOException ioe) {
808 }
catch (IOException ioe) {
824 public static void writeData(String fileName, String data,
boolean append)
826 FileWriter fw =
null;
828 fw =
new FileWriter(
new File(fileName), append);
831 }
catch (IOException ioe) {
838 }
catch (IOException ioe) {
858 List<String> propNames =
new ArrayList<String>(Arrays.asList(
862 List<String> optionalPropNames =
new ArrayList<String>(Arrays.asList(
868 propNames.addAll(optionalPropNames);
870 file.getAbsolutePath(), propNames);
872 List<CandidateLW> items =
new ArrayList<CandidateLW>();
873 for (Map<String, Object> props : propsPerItem)
881 Object nameObj = props.get(CDKConstants.TITLE);
885 + CDKConstants.TITLE +
" is null!");
888 nameObj.toString(),file.getAbsolutePath());
890 for (String propName : optionalPropNames)
892 Object obj = props.get(propName);
898 item.
setFitness(Double.parseDouble(obj.toString()));
910 item.
setLevel(Integer.parseInt(obj.toString()));
932 double[] vals =
new double[4];
933 ArrayList<String> txt =
readList(file.getAbsolutePath());
934 for (String line : txt) {
935 if (line.trim().length() < 8) {
939 String key = line.toUpperCase().trim().substring(0, 8);
942 vals[0] = Double.parseDouble(line.split(
"\\s+")[1]);
946 vals[1] = Double.parseDouble(line.split(
"\\s+")[1]);
950 vals[2] = Double.parseDouble(line.split(
"\\s+")[1]);
954 vals[3] = Double.parseDouble(line.split(
"\\s+")[1]);
974 List<String> vals =
new ArrayList<String>();
975 ArrayList<String> txt =
readList(file.getAbsolutePath());
976 for (String line : txt)
978 if (!line.contains(
FS))
981 String[] words = line.trim().split(
"\\s+");
982 if (words.length < 5)
1007 List<CandidateLW> members =
new ArrayList<CandidateLW>();
1008 List<String> txt =
readList(file.getAbsolutePath());
1011 for (
int i=1; i<txt.size(); i++)
1013 String line = txt.get(i);
1018 if (line.startsWith(
"#"))
1024 String[] words = line.trim().split(
"\\s+");
1025 String pathname =
"nofile";
1026 if (words.length >= 5)
1028 pathname = words[4];
1031 member.
setFitness(Double.parseDouble(words[3]));
1032 members.add(member);
1046 public static ArrayList<String>
readList(String fileName)
1062 public static ArrayList<String>
readList(String fileName,
1064 ArrayList<String> lst =
new ArrayList<>();
1065 BufferedReader br =
null;
1068 br =
new BufferedReader(
new FileReader(fileName));
1069 while ((line = br.readLine()) !=
null) {
1070 if (line.trim().length() == 0) {
1073 lst.add(line.trim());
1075 }
catch (IOException ioe) {
1082 }
catch (IOException ioe) {
1087 if (lst.isEmpty() && !allowEmpty) {
1104 StringBuilder sb =
new StringBuilder();
1105 BufferedReader br =
null;
1108 br =
new BufferedReader(
new FileReader(fileName));
1109 while ((line = br.readLine()) !=
null) {
1110 sb.append(line).append(
NL);
1112 }
catch (IOException ioe) {
1119 }
catch (IOException ioe) {
1124 return sb.toString();
1140 List<Map<String,Object>> results =
new ArrayList<Map<String,Object>>();
1142 for (IAtomContainer iac : iacs)
1144 Map<String,Object> properties =
new HashMap<String,Object>();
1145 for (String propName : propNames)
1147 properties.put(propName, iac.getProperty(propName));
1149 results.add(properties);
1165 StringWriter stringWriter =
new StringWriter();
1166 MDLV2000Writer mw =
null;
1168 mw =
new MDLV2000Writer(stringWriter);
1170 }
catch (CDKException cdke) {
1177 }
catch (IOException ioe) {
1182 String MoleculeString = stringWriter.toString();
1186 String Moleculelines[] = MoleculeString.split(
"\\r?\\n");
1188 StringBuilder sb =
new StringBuilder(1024);
1189 sb.append(
"var molFile = '");
1190 for (
int i = 0; i < Moleculelines.length; i++) {
1191 sb.append(Moleculelines[i]);
1195 return sb.toString();
1201 Set<APClass> allCLasses =
new HashSet<APClass>();
1206 allCLasses.add(ap.getAPClass());
1211 System.out.println(
"Could not read data from '" + fragLib +
"'. "
1212 +
"Cause: " + e.getMessage());
1229 HashMap<
APClass, ArrayList<APClass>> cpMap,
1230 HashMap<APClass, APClass> capMap,
1232 DateFormat dateFormat =
new SimpleDateFormat(
"dd/MM/yy HH:mm:ss");
1233 Date date =
new Date();
1234 String dateStr = dateFormat.format(date);
1236 StringBuilder sb =
new StringBuilder();
1238 sb.append(
" Compatibility matrix data").append(
NL);
1240 sb.append(
" Written by DENOPTIM-GUI on ").append(dateStr).append(
NL);
1242 sb.append(
" APCLass Compatibility rules").append(
NL);
1243 SortedSet<APClass> keysCPMap =
new TreeSet<APClass>();
1244 keysCPMap.addAll(cpMap.keySet());
1245 for (
APClass srcAPC : keysCPMap) {
1247 sb.append(srcAPC).append(
" ");
1248 for (
int i = 0; i < cpMap.get(srcAPC).size(); i++) {
1249 APClass trgAPC = cpMap.get(srcAPC).get(i);
1251 if (i != (cpMap.get(srcAPC).size() - 1)) {
1260 sb.append(
" Capping rules").append(
NL);
1261 SortedSet<APClass> keysCap =
new TreeSet<APClass>();
1262 keysCap.addAll(capMap.keySet());
1265 sb.append(apc).append(
" ").append(capMap.get(apc)).append(
NL);
1269 sb.append(
" Forbidden ends").append(
NL);
1270 SortedSet<APClass> sortedFE =
new TreeSet<APClass>();
1271 sortedFE.addAll(ends);
1272 for (
APClass apc : sortedFE) {
1274 sb.append(apc).append(
" ").append(
NL);
1292 ArrayList<APClass>> compatMap,
1293 HashMap<APClass, APClass> cappingMap, Set<APClass> forbiddenEndList)
1296 BufferedReader br =
null;
1299 br =
new BufferedReader(
new FileReader(fileName));
1300 while ((line = br.readLine()) !=
null) {
1301 if (line.trim().length() == 0) {
1310 String str[] = line.split(
"\\s+");
1311 if (str.length < 3) {
1312 String err =
"Incomplete APClass compatibility line '"
1318 ArrayList<APClass> trgAPCs =
new ArrayList<APClass>();
1319 for (String s : str[2].split(
","))
1323 compatMap.put(srcAPC, trgAPCs);
1326 String str[] = line.split(
"\\s+");
1327 if (str.length != 3) {
1328 String err =
"Incomplete capping line '"
1334 cappingMap.put(srcAPC, trgAPC);
1336 if (line.startsWith(
1338 String str[] = line.split(
"\\s+");
1339 if (str.length != 2) {
1340 for (
int is = 1; is < str.length; is++) {
1341 forbiddenEndList.add(
1351 }
catch (NumberFormatException | IOException nfe) {
1358 }
catch (IOException ioe) {
1363 if (compatMap.isEmpty()) {
1364 String err =
"No reaction compatibility data found in file: ";
1386 HashMap<
APClass, ArrayList<APClass>> rcCompatMap)
1388 BufferedReader br =
null;
1391 br =
new BufferedReader(
new FileReader(fileName));
1392 while ((line = br.readLine()) !=
null) {
1393 if (line.trim().length() == 0) {
1402 String str[] = line.split(
"\\s+");
1403 if (str.length < 3) {
1404 String err =
"Incomplete reaction compatibility data.";
1410 String strRcn[] = str[2].split(
",");
1411 for (
int i = 0; i < strRcn.length; i++) {
1412 strRcn[i] = strRcn[i].trim();
1415 if (rcCompatMap.containsKey(srcAPC)) {
1416 rcCompatMap.get(srcAPC).add(trgAPC);
1418 ArrayList<APClass> list =
new ArrayList<APClass>();
1420 rcCompatMap.put(srcAPC, list);
1423 if (rcCompatMap.containsKey(trgAPC)) {
1424 rcCompatMap.get(trgAPC).add(srcAPC);
1426 ArrayList<APClass> list =
new ArrayList<APClass>();
1428 rcCompatMap.put(trgAPC, list);
1433 }
catch (NumberFormatException | IOException nfe) {
1440 }
catch (IOException ioe) {
1445 if (rcCompatMap.isEmpty()) {
1446 String err =
"No reaction compatibility data found in file: ";
1485 String filename = file.getAbsolutePath();
1486 ArrayList<Candidate> candidates =
new ArrayList<>();
1487 ArrayList<IAtomContainer> iacs =
readSDFFile(file.getAbsolutePath());
1491 if (file.getParentFile()!=
null
1492 && file.getParentFile().getName().startsWith(
1495 String genFolderName = file.getParentFile().getName();
1496 genID = Integer.valueOf(genFolderName.substring(
1500 for (IAtomContainer iac : iacs) {
1505 candidates.add(cand);
1520 List<Candidate> popMembers,
boolean append)
1523 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1525 file =
new File(file.getAbsoluteFile() +
"."
1528 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
1531 lst.add(g.getFitnessProviderOutputRepresentation());
1549 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1551 file =
new File(file.getAbsoluteFile() +
"."
1555 candidate.getFitnessProviderOutputRepresentation(), append);
1570 ArrayList<GraphEdit> graphEditTasks =
new ArrayList<>();
1573 BufferedReader br =
null;
1576 br =
new BufferedReader(
new FileReader(fileName));
1577 graphEditTasks = reader.fromJson(br,
1578 new TypeToken<ArrayList<GraphEdit>>(){}.getType());
1580 catch (FileNotFoundException fnfe)
1584 catch (JsonSyntaxException jse)
1586 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1587 if (jse.getMessage().contains(msg))
1594 br =
new BufferedReader(
new FileReader(fileName));
1596 catch (FileNotFoundException fnfe)
1599 }
catch (IOException ioe)
1603 GraphEdit graphEditTask = reader.fromJson(br,
1605 graphEditTasks.add(graphEditTask);
1607 jse.printStackTrace();
1609 +
"that defines a graph enditing task.",jse);
1619 }
catch (IOException ioe) {
1624 return graphEditTasks;
1664 inFile.getAbsolutePath());
1668 inFile.getAbsolutePath());
1673 +
"JSON format instead.");
1677 inFile.getAbsolutePath());
1680 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
1683 for (
Vertex v : vertexes)
1687 graphs.add(((
Template)v).getInnerGraph());
1690 System.out.println(
"WARNING: Reading graphs from "
1692 +
"templates' inner graphs. Importing "
1693 + graphs.size() +
" graphs "
1694 +
"from " + vertexes.size() +
" vertexes.");
1698 throw new Exception(
"Format '" + format +
"' could not be used "
1699 +
"to read graphs from file '" + inFile +
"'.");
1715 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1718 for (IAtomContainer mol : mols)
1788 +
"files containing graphs must include the "
1791 String msg =
"Attempt to load graph form "
1792 +
"SDF that has no '" + DENOPTIMConstants.GRAPHJSONTAG
1796 msg = msg +
" Check molecule " + molId;
1797 if (!fileName.isEmpty())
1799 msg = msg +
" in the SDF file '" + fileName +
"'";
1806 String js = json.toString();
1810 }
catch (Exception e)
1812 String msg = e.getMessage();
1815 msg = msg +
" Check molecule " + molId;
1816 if (!fileName.isEmpty())
1818 msg = msg +
" in the SDF file '" + fileName +
"'";
1842 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1843 BufferedReader br =
null;
1846 br =
new BufferedReader(
new FileReader(fileName));
1847 while ((line = br.readLine()) !=
null) {
1848 if (line.trim().length() == 0) {
1860 }
catch (Throwable t) {
1861 String msg =
"Cannot convert string to DENOPTIMGraph. "
1862 +
"Check line '" + line.trim() +
"'";
1863 logger.log(Level.SEVERE, msg);
1868 }
catch (IOException ioe) {
1869 String msg =
"Cannot read file " + fileName;
1870 logger.log(Level.SEVERE, msg);
1877 }
catch (IOException ioe) {
1898 ArrayList<Vertex> result =
new ArrayList<Vertex>();
1901 BufferedReader br =
null;
1904 br =
new BufferedReader(
new FileReader(fileName));
1905 result = reader.fromJson(br,
1906 new TypeToken<ArrayList<Vertex>>(){}.getType());
1908 catch (FileNotFoundException fnfe)
1912 catch (JsonSyntaxException jse)
1914 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1915 if (jse.getMessage().contains(msg))
1922 br =
new BufferedReader(
new FileReader(fileName));
1924 catch (FileNotFoundException fnfe)
1927 }
catch (IOException ioe)
1935 + fileName +
"'.", jse);
1945 }
catch (IOException ioe) {
1964 ArrayList<DGraph> list_of_graphs =
new ArrayList<DGraph>();
1967 BufferedReader br =
null;
1970 br =
new BufferedReader(
new FileReader(fileName));
1971 list_of_graphs = reader.fromJson(br,
1972 new TypeToken<ArrayList<DGraph>>(){}.getType());
1974 catch (FileNotFoundException fnfe)
1978 catch (JsonSyntaxException jse)
1980 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1981 if (jse.getMessage().contains(msg))
1988 br =
new BufferedReader(
new FileReader(fileName));
1990 catch (FileNotFoundException fnfe)
1993 }
catch (IOException ioe)
1998 list_of_graphs.add(g);
2001 +
"JSON '" + fileName +
"'", jse);
2011 }
catch (IOException ioe) {
2016 return list_of_graphs;
2033 if (FilenameUtils.getExtension(file.getName()).equals(
""))
2035 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2066 List<DGraph> modGraphs, Logger logger,
Randomizer randomizer)
2069 if (FilenameUtils.getExtension(file.getName()).equals(
""))
2071 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2100 List<DGraph> graphs, Logger logger,
Randomizer randomizer)
2118 boolean append,
boolean make3D, Logger logger,
Randomizer randomizer)
2121 List<DGraph> lst =
new ArrayList<>(1);
2137 boolean append, Logger logger,
Randomizer randomizer)
2140 ArrayList<DGraph> lst =
new ArrayList<>(1);
2156 List<DGraph> graphs,
boolean append,
2175 List<DGraph> modGraphs,
boolean append,
boolean make3D,
2178 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
2179 for (
DGraph g : modGraphs)
2182 IAtomContainer iac =
builder.newAtomContainer();
2187 }
catch (Throwable t) {
2188 t.printStackTrace();
2189 logger.log(Level.WARNING,
"Couldn't make 3D-tree "
2190 +
"representation: " + t.getMessage());
2212 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
2230 writeData(file.getAbsolutePath(), writer.toJson(graphs),
false);
2247 writeData(file.getAbsolutePath(), writer.toJson(graphs), append);
2263 writeData(fileName, graph.toString(), append);
2277 Map<File, FileFormat> map =
new LinkedHashMap<File, FileFormat>();
2288 String[] parts = line.split(
"\\s+");
2289 String ffStr = parts[0];
2294 }
catch (Exception e)
2297 +
"' to a known file format.");
2299 String fileName = line.substring(ffStr.length()).trim();
2302 map.put(
new File(fileName), ff);
2308 +
"fetch list of recent files.", e);
2309 map =
new HashMap<File, FileFormat>();
2333 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2339 file.getAbsolutePath(),bbt);
2344 file.getAbsolutePath());
2348 ArrayList<DGraph> lstGraphs =
2350 for (
DGraph g : lstGraphs)
2359 ArrayList<DGraph> lstGraphs2 =
2361 for (
DGraph g : lstGraphs2)
2371 +
"' could not be used to "
2372 +
"read in vertices from file '" + file +
"'.");
2389 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2402 +
" in file " + fileName,e);
2430 LinkedHashMap<String, String> allFormulae =
new LinkedHashMap<String,String>();
2431 BufferedReader buffRead =
null;
2434 buffRead =
new BufferedReader(
new FileReader(file));
2435 String lineAll =
null;
2436 String refcode =
"";
2437 String formula =
"";
2438 while ((lineAll = buffRead.readLine()) !=
null)
2440 String[] lineArgs = lineAll.split(
":");
2442 if (lineArgs[0].equals(
"REFCODE"))
2443 refcode = lineArgs[1].trim();
2446 if (lineArgs[0].equals(
" Formula"))
2448 formula = lineArgs[1].trim();
2450 allFormulae.put(refcode,formula);
2456 }
catch (FileNotFoundException fnf) {
2458 }
catch (IOException ioex) {
2462 if (buffRead !=
null)
2464 }
catch (IOException e) {
2488 ArrayList<String> cutRulLines =
new ArrayList<String>();
2492 while ((line = reader.readLine()) !=
null)
2495 cutRulLines.add(line.trim());
2497 }
catch (IOException e)
2505 }
catch (IOException e)
2526 ArrayList<String> allLines =
readList(file.getAbsolutePath());
2529 ArrayList<String> cutRulLines =
new ArrayList<String>();
2531 .filter(line -> line.trim().startsWith(
2533 .forEach(line -> cutRulLines.add(line.trim()));
2536 + file.getAbsolutePath()+
"'");
2557 Set<Integer> usedPriorities =
new HashSet<Integer>();
2558 for (
int i = 0; i<cutRulLines.size(); i++)
2560 String[] words = cutRulLines.get(i).split(
"\\s+");
2561 String name = words[1];
2562 if (words.length < 6)
2565 +
" Found " + words.length +
" parts inctead of 6."
2566 +
"Check line '" + cutRulLines.get(i) +
"'"
2567 +
"in " + source +
".");
2571 ArrayList<String> opts =
new ArrayList<String>();
2572 if (words.length >= 7)
2574 for (
int wi=6; wi<words.length; wi++)
2576 opts.add(words[wi]);
2580 int priority = Integer.parseInt(words[2]);
2581 if (usedPriorities.contains(priority))
2584 +
" Duplicate priority index " + priority +
". "
2585 +
"Check line '" + cutRulLines.get(i) +
"'"
2586 +
"in " + source +
".");
2588 usedPriorities.add(priority);
2601 Collections.sort(cutRules,
new Comparator<CuttingRule>() {
2623 StringBuilder sb =
new StringBuilder();
2627 sb.append(r.getName()).append(
" ");
2628 sb.append(r.getPriority()).append(
" ");
2629 sb.append(r.getSMARTSAtom0()).append(
" ");
2630 sb.append(r.getSMARTSAtom1()).append(
" ");
2631 sb.append(r.getSMARTSBnd()).append(
" ");
2632 if (r.getOptions()!=
null)
2634 for (String opt : r.getOptions())
2635 sb.append(opt).append(
" ");
2639 writeData(file.getAbsolutePath(), sb.toString(),
false);
2654 PrintWriter pw =
null;
2657 fw =
new FileWriter(f1,
true);
2658 bw =
new BufferedWriter(fw);
2659 pw =
new PrintWriter(bw);
2660 for (File inFile : files)
2663 BufferedReader br =
null;
2666 fr =
new FileReader(inFile);
2667 br =
new BufferedReader(fr);
2669 while ((line = br.readLine()) !=
null)
2697 List<BridgeHeadFindingRule> rules =
null;
2698 BufferedReader br =
null;
2700 br =
new BufferedReader(
new FileReader(fileName));
2703 catch (FileNotFoundException fnfe)
2706 }
catch (IOException ioe)
2717 }
catch (IOException ioe) {
2736 BufferedReader br)
throws IOException
2738 List<BridgeHeadFindingRule> rules =
new ArrayList<>();
2742 rules = reader.fromJson(br,
2743 new TypeToken<ArrayList<BridgeHeadFindingRule>>(){}.getType());
2765 logger.log(Level.ALL,
"ALL");
2766 logger.log(Level.SEVERE,
"SEVERE");
2767 logger.log(Level.WARNING,
"WARN");
2768 logger.log(Level.INFO,
"INFO");
2769 logger.log(Level.CONFIG,
"CONGIF");
2770 logger.log(Level.FINE,
"Fine");
2771 logger.log(Level.FINER,
"FINER");
2772 logger.log(Level.FINEST,
"FIENEST");
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)
This differs from DefaultChemObjectReaderErrorHandler just by ignoring messages about invalid symbol.
PartlySilencedChemObjReaderErrorHandler(final Class<?> clazz)
Constructs a new instance using a given class as the source for logging purposes.
void handleFatalError(String message, int row, int colStart, int colEnd)
boolean isInvalidSymbolMessage(String message)
void handleError(String message, Exception exception)
void handleFatalError(String message, int row, int colStart, int colEnd, Exception exception)
void handleFatalError(String message, Exception exception)
final ILoggingTool logger
void handleFatalError(String message)
void handleError(String message)
PartlySilencedChemObjReaderErrorHandler(final ILoggingTool logger)
Constructs a new instance using the provided logging tool.
void handleError(String message, int row, int colStart, int colEnd, Exception exception)
void handleError(String message, int row, int colStart, int colEnd)
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 void scanLoggingLevels(Logger logger)
Utility to trigger logging at all known levels.
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.