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.text.DateFormat;
32import java.text.SimpleDateFormat;
33import java.util.ArrayList;
34import java.util.Arrays;
35import java.util.Collections;
36import java.util.Comparator;
38import java.util.HashMap;
39import java.util.HashSet;
40import java.util.Hashtable;
41import java.util.LinkedHashMap;
45import java.util.SortedSet;
46import java.util.TreeSet;
47import java.util.logging.Level;
48import java.util.logging.Logger;
50import org.apache.commons.io.FilenameUtils;
51import org.jmol.adapter.smarter.SmarterJmolAdapter;
52import org.jmol.viewer.Viewer;
53import org.openscience.cdk.AtomContainerSet;
54import org.openscience.cdk.CDKConstants;
55import org.openscience.cdk.DefaultChemObjectBuilder;
56import org.openscience.cdk.exception.CDKException;
57import org.openscience.cdk.interfaces.IAtomContainer;
58import org.openscience.cdk.interfaces.IAtomContainerSet;
59import org.openscience.cdk.interfaces.IChemObjectBuilder;
60import org.openscience.cdk.io.DefaultChemObjectReader;
61import org.openscience.cdk.io.FormatFactory;
62import org.openscience.cdk.io.IChemObjectReaderErrorHandler;
63import org.openscience.cdk.io.Mol2Writer;
64import org.openscience.cdk.io.SDFWriter;
65import org.openscience.cdk.io.XYZWriter;
66import org.openscience.cdk.io.formats.CIFFormat;
67import org.openscience.cdk.io.formats.IChemFormat;
68import org.openscience.cdk.io.iterator.IteratingSDFReader;
69import org.openscience.cdk.silent.SilentChemObjectBuilder;
70import org.openscience.cdk.tools.ILoggingTool;
71import org.openscience.cdk.tools.LoggingToolFactory;
73import com.google.gson.Gson;
74import com.google.gson.JsonSyntaxException;
75import com.google.gson.reflect.TypeToken;
77import denoptim.constants.DENOPTIMConstants;
78import denoptim.exception.DENOPTIMException;
79import denoptim.files.FileFormat;
80import denoptim.files.FileUtils;
81import denoptim.files.UndetectedFileFormatException;
82import denoptim.fragmenter.BridgeHeadFindingRule;
83import denoptim.fragspace.FragmentSpace;
84import denoptim.graph.APClass;
85import denoptim.graph.AttachmentPoint;
86import denoptim.graph.Candidate;
87import denoptim.graph.CandidateLW;
88import denoptim.graph.DGraph;
89import denoptim.graph.Template;
90import denoptim.graph.Vertex;
91import denoptim.graph.Vertex.BBType;
92import denoptim.json.DENOPTIMgson;
93import denoptim.logging.StaticLogger;
94import denoptim.molecularmodeling.ThreeDimTreeBuilder;
95import denoptim.programs.fragmenter.CuttingRule;
96import denoptim.utils.GraphConversionTool;
97import denoptim.utils.GraphEdit;
98import denoptim.utils.GraphUtils;
99import denoptim.utils.Randomizer;
115 public static final String
FS = System.getProperty(
"file.separator");
120 public static final String
NL = System.getProperty(
"line.separator");
122 private static final IChemObjectBuilder
builder =
123 SilentChemObjectBuilder.getInstance();
140 File file =
new File(pathname);
186 data = graphs.get(0);
197 data = graphs.get(0);
213 + format +
"' cannot be loaded yet. Please, contact"
214 +
"the development team.");
237 ArrayList<Candidate> cands =
new ArrayList<Candidate>();
239 String genSummaryParentDir = file.getParent();
240 for (String candPathname : pathnames)
242 File candFile =
new File(candPathname);
243 if (candFile.exists())
246 }
else if (genSummaryParentDir!=
null) {
249 String runFolderPathname =
250 candFile.getParentFile()
252 if (runFolderPathname==
null)
254 +
"folder for '"+ genSummaryParentDir +
"'");
256 String genAndMolPath = candFile.getAbsolutePath()
257 .substring(runFolderPathname.length());
260 genSummaryParentDir+genAndMolPath)).
get(0));
282 List<IAtomContainer> results =
null;
284 FileReader formatReader =
new FileReader(file);
285 IChemFormat chemFormat =
new FormatFactory().guessFormat(
286 new BufferedReader(formatReader));
287 formatReader.close();
289 if (chemFormat instanceof CIFFormat)
310 Map<String, Object> info =
new Hashtable<String, Object>();
311 info.put(
"adapter",
new SmarterJmolAdapter());
312 info.put(
"isApp",
false);
313 info.put(
"silent",
"");
314 Viewer v =
new Viewer(info);
315 v.loadModelFromFile(
null, file.getAbsolutePath(),
null,
null,
316 false,
null,
null,
null, 0,
" ");
318 v.scriptWait(
"write " + tmp +
" as sdf");
339 public static ArrayList<IAtomContainer>
readSDFFile(String fileName)
342 ArrayList<IAtomContainer> lstContainers =
new ArrayList<>();
344 File file =
new File(fileName);
345 IteratingSDFReader reader =
null;
347 reader =
new IteratingSDFReader(
348 new BufferedReader(
new FileReader(file)),
349 DefaultChemObjectBuilder.getInstance());
351 DefaultChemObjectReader.class));
352 while (reader.hasNext()) {
353 lstContainers.add((IAtomContainer)reader.next());
355 }
catch (IOException cdke) {
359 if (reader !=
null) {
362 }
catch (IOException ioe) {
367 if (lstContainers.isEmpty()) {
371 return lstContainers;
393 this(LoggingToolFactory.createLoggingTool(clazz));
416 public void handleError(String message,
int row,
int colStart,
int colEnd) {
421 public void handleError(String message,
int row,
int colStart,
int colEnd, Exception exception) {
432 logger.fatal(message +
", " + exception);
437 logger.fatal(message +
", row " + row +
" column " + colStart +
"-" + colEnd);
441 public void handleFatalError(String message,
int row,
int colStart,
int colEnd, Exception exception) {
442 logger.fatal(message +
", row " + row +
" column " + colStart +
"-" + colEnd +
", " + exception);
447 return message.contains(
"invalid symbol:");
480 ArrayList<Vertex> lst =
new ArrayList<Vertex>();
498 if (FilenameUtils.getExtension(file.getName()).equals(
""))
500 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
552 file.getAbsolutePath());
553 allVertexes.addAll(vertexes);
554 writeData(file.getAbsolutePath(), writer.toJson(allVertexes),
false);
556 writeData(file.getAbsolutePath(), writer.toJson(vertexes),
false);
573 List<Vertex> lst =
new ArrayList<Vertex>();
589 List<Vertex> vertexes,
boolean append)
592 List<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
595 lst.add(v.getIAtomContainer());
611 List<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
625 public static void writeSDFFile(String fileName, List<IAtomContainer> mols)
640 public static void writeSDFFile(String fileName, List<IAtomContainer> mols,
643 SDFWriter sdfWriter =
null;
645 IAtomContainerSet molSet =
new AtomContainerSet();
646 for (
int idx = 0; idx < mols.size(); idx++) {
647 molSet.addAtomContainer(mols.get(idx));
649 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName),append));
650 sdfWriter.write(molSet);
651 }
catch (CDKException | IOException cdke) {
655 if (sdfWriter !=
null) {
658 }
catch (IOException ioe) {
676 SDFWriter sdfWriter =
null;
678 sdfWriter =
new SDFWriter(
new FileWriter(
new File(fileName), append));
679 sdfWriter.write(mol);
680 }
catch (CDKException | IOException cdke) {
684 if (sdfWriter !=
null) {
687 }
catch (IOException ioe) {
697 Mol2Writer mol2Writer =
null;
699 mol2Writer =
new Mol2Writer(
new FileWriter(
new File(fileName), append));
700 mol2Writer.write(mol);
701 }
catch (CDKException cdke) {
703 }
catch (IOException ioe) {
707 if (mol2Writer !=
null) {
710 }
catch (IOException ioe) {
720 XYZWriter xyzWriter =
null;
722 xyzWriter =
new XYZWriter(
new FileWriter(
new File(fileName), append));
723 xyzWriter.write(mol);
724 }
catch (CDKException cdke) {
726 }
catch (IOException ioe) {
730 if (xyzWriter !=
null) {
733 }
catch (IOException ioe) {
752 FileWriter fw =
null;
754 fw =
new FileWriter(
new File(fileName), append);
755 for (
int i = 0; i < smiles.length; i++) {
756 fw.write(smiles[i] +
NL);
759 }
catch (IOException ioe) {
766 }
catch (IOException ioe) {
785 FileWriter fw =
null;
787 fw =
new FileWriter(
new File(fileName), append);
788 fw.write(smiles +
NL);
790 }
catch (IOException ioe) {
797 }
catch (IOException ioe) {
813 public static void writeData(String fileName, String data,
boolean append)
815 FileWriter fw =
null;
817 fw =
new FileWriter(
new File(fileName), append);
820 }
catch (IOException ioe) {
827 }
catch (IOException ioe) {
847 List<String> propNames =
new ArrayList<String>(Arrays.asList(
851 List<String> optionalPropNames =
new ArrayList<String>(Arrays.asList(
857 propNames.addAll(optionalPropNames);
859 file.getAbsolutePath(), propNames);
861 List<CandidateLW> items =
new ArrayList<CandidateLW>();
862 for (Map<String, Object> props : propsPerItem)
870 Object nameObj = props.get(CDKConstants.TITLE);
874 + CDKConstants.TITLE +
" is null!");
877 nameObj.toString(),file.getAbsolutePath());
879 for (String propName : optionalPropNames)
881 Object obj = props.get(propName);
887 item.
setFitness(Double.parseDouble(obj.toString()));
899 item.
setLevel(Integer.parseInt(obj.toString()));
921 double[] vals =
new double[4];
922 ArrayList<String> txt =
readList(file.getAbsolutePath());
923 for (String line : txt) {
924 if (line.trim().length() < 8) {
928 String key = line.toUpperCase().trim().substring(0, 8);
931 vals[0] = Double.parseDouble(line.split(
"\\s+")[1]);
935 vals[1] = Double.parseDouble(line.split(
"\\s+")[1]);
939 vals[2] = Double.parseDouble(line.split(
"\\s+")[1]);
943 vals[3] = Double.parseDouble(line.split(
"\\s+")[1]);
963 List<String> vals =
new ArrayList<String>();
964 ArrayList<String> txt =
readList(file.getAbsolutePath());
965 for (String line : txt)
967 if (!line.contains(
FS))
970 String[] words = line.trim().split(
"\\s+");
971 if (words.length < 5)
996 List<CandidateLW> members =
new ArrayList<CandidateLW>();
997 List<String> txt =
readList(file.getAbsolutePath());
1000 for (
int i=1; i<txt.size(); i++)
1002 String line = txt.get(i);
1007 if (line.startsWith(
"#"))
1013 String[] words = line.trim().split(
"\\s+");
1014 String pathname =
"nofile";
1015 if (words.length >= 5)
1017 pathname = words[4];
1020 member.
setFitness(Double.parseDouble(words[3]));
1021 members.add(member);
1035 public static ArrayList<String>
readList(String fileName)
1051 public static ArrayList<String>
readList(String fileName,
1053 ArrayList<String> lst =
new ArrayList<>();
1054 BufferedReader br =
null;
1057 br =
new BufferedReader(
new FileReader(fileName));
1058 while ((line = br.readLine()) !=
null) {
1059 if (line.trim().length() == 0) {
1062 lst.add(line.trim());
1064 }
catch (IOException ioe) {
1071 }
catch (IOException ioe) {
1076 if (lst.isEmpty() && !allowEmpty) {
1093 StringBuilder sb =
new StringBuilder();
1094 BufferedReader br =
null;
1097 br =
new BufferedReader(
new FileReader(fileName));
1098 while ((line = br.readLine()) !=
null) {
1099 sb.append(line).append(
NL);
1101 }
catch (IOException ioe) {
1108 }
catch (IOException ioe) {
1113 return sb.toString();
1129 List<Map<String,Object>> results =
new ArrayList<Map<String,Object>>();
1131 for (IAtomContainer iac : iacs)
1133 Map<String,Object> properties =
new HashMap<String,Object>();
1134 for (String propName : propNames)
1136 properties.put(propName, iac.getProperty(propName));
1138 results.add(properties);
1146 Set<APClass> allCLasses =
new HashSet<APClass>();
1151 allCLasses.add(ap.getAPClass());
1156 System.out.println(
"Could not read data from '" + fragLib +
"'. "
1157 +
"Cause: " + e.getMessage());
1174 HashMap<
APClass, ArrayList<APClass>> cpMap,
1175 HashMap<APClass, APClass> capMap,
1177 DateFormat dateFormat =
new SimpleDateFormat(
"dd/MM/yy HH:mm:ss");
1178 Date date =
new Date();
1179 String dateStr = dateFormat.format(date);
1181 StringBuilder sb =
new StringBuilder();
1183 sb.append(
" Compatibility matrix data").append(
NL);
1185 sb.append(
" Written by DENOPTIM-GUI on ").append(dateStr).append(
NL);
1187 sb.append(
" APCLass Compatibility rules").append(
NL);
1188 SortedSet<APClass> keysCPMap =
new TreeSet<APClass>();
1189 keysCPMap.addAll(cpMap.keySet());
1190 for (
APClass srcAPC : keysCPMap) {
1192 sb.append(srcAPC).append(
" ");
1193 for (
int i = 0; i < cpMap.get(srcAPC).size(); i++) {
1194 APClass trgAPC = cpMap.get(srcAPC).get(i);
1196 if (i != (cpMap.get(srcAPC).size() - 1)) {
1204 sb.append(
" Capping rules").append(
NL);
1205 SortedSet<APClass> keysCap =
new TreeSet<APClass>();
1206 keysCap.addAll(capMap.keySet());
1209 sb.append(apc).append(
" ").append(capMap.get(apc)).append(
NL);
1213 sb.append(
" Forbidden ends").append(
NL);
1214 SortedSet<APClass> sortedFE =
new TreeSet<APClass>();
1215 sortedFE.addAll(ends);
1216 for (
APClass apc : sortedFE) {
1218 sb.append(apc).append(
" ").append(
NL);
1236 ArrayList<APClass>> compatMap,
1237 HashMap<APClass, APClass> cappingMap, Set<APClass> forbiddenEndList)
1240 BufferedReader br =
null;
1243 br =
new BufferedReader(
new FileReader(fileName));
1244 while ((line = br.readLine()) !=
null) {
1245 if (line.trim().length() == 0) {
1254 String str[] = line.split(
"\\s+");
1255 if (str.length < 3) {
1256 String err =
"Incomplete APClass compatibility line '"
1262 ArrayList<APClass> trgAPCs =
new ArrayList<APClass>();
1263 for (String s : str[2].split(
","))
1267 compatMap.put(srcAPC, trgAPCs);
1270 String str[] = line.split(
"\\s+");
1271 if (str.length != 3) {
1272 String err =
"Incomplete capping line '"
1278 cappingMap.put(srcAPC, trgAPC);
1280 if (line.startsWith(
1282 String str[] = line.split(
"\\s+");
1283 if (str.length != 2) {
1284 for (
int is = 1; is < str.length; is++) {
1285 forbiddenEndList.add(
1295 }
catch (NumberFormatException | IOException nfe) {
1302 }
catch (IOException ioe) {
1307 if (compatMap.isEmpty()) {
1308 String err =
"No reaction compatibility data found in file: ";
1330 HashMap<
APClass, ArrayList<APClass>> rcCompatMap)
1332 BufferedReader br =
null;
1335 br =
new BufferedReader(
new FileReader(fileName));
1336 while ((line = br.readLine()) !=
null) {
1337 if (line.trim().length() == 0) {
1346 String str[] = line.split(
"\\s+");
1347 if (str.length < 3) {
1348 String err =
"Incomplete reaction compatibility data.";
1354 String strRcn[] = str[2].split(
",");
1355 for (
int i = 0; i < strRcn.length; i++) {
1356 strRcn[i] = strRcn[i].trim();
1359 if (rcCompatMap.containsKey(srcAPC)) {
1360 rcCompatMap.get(srcAPC).add(trgAPC);
1362 ArrayList<APClass> list =
new ArrayList<APClass>();
1364 rcCompatMap.put(srcAPC, list);
1367 if (rcCompatMap.containsKey(trgAPC)) {
1368 rcCompatMap.get(trgAPC).add(srcAPC);
1370 ArrayList<APClass> list =
new ArrayList<APClass>();
1372 rcCompatMap.put(trgAPC, list);
1377 }
catch (NumberFormatException | IOException nfe) {
1384 }
catch (IOException ioe) {
1389 if (rcCompatMap.isEmpty()) {
1390 String err =
"No reaction compatibility data found in file: ";
1429 String filename = file.getAbsolutePath();
1430 ArrayList<Candidate> candidates =
new ArrayList<>();
1431 ArrayList<IAtomContainer> iacs =
readSDFFile(file.getAbsolutePath());
1435 if (file.getParentFile()!=
null
1436 && file.getParentFile().getName().startsWith(
1439 String genFolderName = file.getParentFile().getName();
1440 genID = Integer.valueOf(genFolderName.substring(
1444 for (IAtomContainer iac : iacs) {
1449 candidates.add(cand);
1464 List<Candidate> popMembers,
boolean append)
1467 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1469 file =
new File(file.getAbsoluteFile() +
"."
1472 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
1475 lst.add(g.getFitnessProviderOutputRepresentation());
1493 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1495 file =
new File(file.getAbsoluteFile() +
"."
1499 candidate.getFitnessProviderOutputRepresentation(), append);
1514 ArrayList<GraphEdit> graphEditTasks =
new ArrayList<>();
1517 BufferedReader br =
null;
1520 br =
new BufferedReader(
new FileReader(fileName));
1521 graphEditTasks = reader.fromJson(br,
1522 new TypeToken<ArrayList<GraphEdit>>(){}.getType());
1524 catch (FileNotFoundException fnfe)
1528 catch (JsonSyntaxException jse)
1530 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1531 if (jse.getMessage().contains(msg))
1538 br =
new BufferedReader(
new FileReader(fileName));
1540 catch (FileNotFoundException fnfe)
1543 }
catch (IOException ioe)
1547 GraphEdit graphEditTask = reader.fromJson(br,
1549 graphEditTasks.add(graphEditTask);
1551 jse.printStackTrace();
1553 +
"that defines a graph enditing task.",jse);
1563 }
catch (IOException ioe) {
1568 return graphEditTasks;
1608 inFile.getAbsolutePath());
1612 inFile.getAbsolutePath());
1617 +
"JSON format instead.");
1621 inFile.getAbsolutePath());
1624 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
1627 for (
Vertex v : vertexes)
1631 graphs.add(((
Template)v).getInnerGraph());
1634 System.out.println(
"WARNING: Reading graphs from "
1636 +
"templates' inner graphs. Importing "
1637 + graphs.size() +
" graphs "
1638 +
"from " + vertexes.size() +
" vertexes.");
1642 throw new Exception(
"Format '" + format +
"' could not be used "
1643 +
"to read graphs from file '" + inFile +
"'.");
1659 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1662 for (IAtomContainer mol : mols)
1732 +
"files containing graphs must include the "
1735 String msg =
"Attempt to load graph form "
1736 +
"SDF that has no '" + DENOPTIMConstants.GRAPHJSONTAG
1740 msg = msg +
" Check molecule " + molId;
1741 if (!fileName.isEmpty())
1743 msg = msg +
" in the SDF file '" + fileName +
"'";
1750 String js = json.toString();
1754 }
catch (Exception e)
1756 String msg = e.getMessage();
1759 msg = msg +
" Check molecule " + molId;
1760 if (!fileName.isEmpty())
1762 msg = msg +
" in the SDF file '" + fileName +
"'";
1786 ArrayList<DGraph> lstGraphs =
new ArrayList<DGraph>();
1787 BufferedReader br =
null;
1790 br =
new BufferedReader(
new FileReader(fileName));
1791 while ((line = br.readLine()) !=
null) {
1792 if (line.trim().length() == 0) {
1804 }
catch (Throwable t) {
1805 String msg =
"Cannot convert string to DENOPTIMGraph. "
1806 +
"Check line '" + line.trim() +
"'";
1807 logger.log(Level.SEVERE, msg);
1812 }
catch (IOException ioe) {
1813 String msg =
"Cannot read file " + fileName;
1814 logger.log(Level.SEVERE, msg);
1821 }
catch (IOException ioe) {
1842 ArrayList<Vertex> result =
new ArrayList<Vertex>();
1845 BufferedReader br =
null;
1848 br =
new BufferedReader(
new FileReader(fileName));
1849 result = reader.fromJson(br,
1850 new TypeToken<ArrayList<Vertex>>(){}.getType());
1852 catch (FileNotFoundException fnfe)
1856 catch (JsonSyntaxException jse)
1858 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1859 if (jse.getMessage().contains(msg))
1866 br =
new BufferedReader(
new FileReader(fileName));
1868 catch (FileNotFoundException fnfe)
1871 }
catch (IOException ioe)
1879 + fileName +
"'.", jse);
1889 }
catch (IOException ioe) {
1908 ArrayList<DGraph> list_of_graphs =
new ArrayList<DGraph>();
1911 BufferedReader br =
null;
1914 br =
new BufferedReader(
new FileReader(fileName));
1915 list_of_graphs = reader.fromJson(br,
1916 new TypeToken<ArrayList<DGraph>>(){}.getType());
1918 catch (FileNotFoundException fnfe)
1922 catch (JsonSyntaxException jse)
1924 String msg =
"Expected BEGIN_ARRAY but was BEGIN_OBJECT";
1925 if (jse.getMessage().contains(msg))
1932 br =
new BufferedReader(
new FileReader(fileName));
1934 catch (FileNotFoundException fnfe)
1937 }
catch (IOException ioe)
1942 list_of_graphs.add(g);
1945 +
"JSON '" + fileName +
"'", jse);
1955 }
catch (IOException ioe) {
1960 return list_of_graphs;
1994 if (FilenameUtils.getExtension(file.getName()).equals(
""))
1996 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2027 List<DGraph> modGraphs, Logger logger,
Randomizer randomizer)
2030 if (FilenameUtils.getExtension(file.getName()).equals(
""))
2032 file =
new File(file.getAbsoluteFile()+
"."+format.getExtension());
2061 List<DGraph> graphs, Logger logger,
Randomizer randomizer)
2079 boolean append,
boolean make3D, Logger logger,
Randomizer randomizer)
2082 List<DGraph> lst =
new ArrayList<>(1);
2098 boolean append, Logger logger,
Randomizer randomizer)
2101 ArrayList<DGraph> lst =
new ArrayList<>(1);
2117 List<DGraph> graphs,
boolean append,
2136 List<DGraph> modGraphs,
boolean append,
boolean make3D,
2139 ArrayList<IAtomContainer> lst =
new ArrayList<IAtomContainer>();
2140 for (
DGraph g : modGraphs)
2143 IAtomContainer iac =
builder.newAtomContainer();
2148 }
catch (Throwable t) {
2149 t.printStackTrace();
2150 logger.log(Level.WARNING,
"Couldn't make 3D-tree "
2151 +
"representation: " + t.getMessage());
2173 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
2191 writeData(file.getAbsolutePath(), writer.toJson(graphs),
false);
2208 writeData(file.getAbsolutePath(), writer.toJson(graphs), append);
2224 writeData(fileName, graph.toString(), append);
2238 Map<File, FileFormat> map =
new LinkedHashMap<File, FileFormat>();
2249 String[] parts = line.split(
"\\s+");
2250 String ffStr = parts[0];
2255 }
catch (Exception e)
2258 +
"' to a known file format.");
2260 String fileName = line.substring(ffStr.length()).trim();
2263 map.put(
new File(fileName), ff);
2269 +
"fetch list of recent files.", e);
2270 map =
new HashMap<File, FileFormat>();
2294 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2300 file.getAbsolutePath(),bbt);
2305 file.getAbsolutePath());
2309 ArrayList<DGraph> lstGraphs =
2311 for (
DGraph g : lstGraphs)
2320 ArrayList<DGraph> lstGraphs2 =
2322 for (
DGraph g : lstGraphs2)
2332 +
"' could not be used to "
2333 +
"read in vertices from file '" + file +
"'.");
2350 ArrayList<Vertex> vertexes =
new ArrayList<Vertex>();
2363 +
" in file " + fileName,e);
2391 LinkedHashMap<String, String> allFormulae =
new LinkedHashMap<String,String>();
2392 BufferedReader buffRead =
null;
2395 buffRead =
new BufferedReader(
new FileReader(file));
2396 String lineAll =
null;
2397 String refcode =
"";
2398 String formula =
"";
2399 while ((lineAll = buffRead.readLine()) !=
null)
2401 String[] lineArgs = lineAll.split(
":");
2403 if (lineArgs[0].equals(
"REFCODE"))
2404 refcode = lineArgs[1].trim();
2407 if (lineArgs[0].equals(
" Formula"))
2409 formula = lineArgs[1].trim();
2411 allFormulae.put(refcode,formula);
2417 }
catch (FileNotFoundException fnf) {
2419 }
catch (IOException ioex) {
2423 if (buffRead !=
null)
2425 }
catch (IOException e) {
2449 ArrayList<String> cutRulLines =
new ArrayList<String>();
2453 while ((line = reader.readLine()) !=
null)
2456 cutRulLines.add(line.trim());
2458 }
catch (IOException e)
2466 }
catch (IOException e)
2487 ArrayList<String> allLines =
readList(file.getAbsolutePath());
2490 ArrayList<String> cutRulLines =
new ArrayList<String>();
2492 .filter(line -> line.trim().startsWith(
2494 .forEach(line -> cutRulLines.add(line.trim()));
2497 + file.getAbsolutePath()+
"'");
2518 Set<Integer> usedPriorities =
new HashSet<Integer>();
2519 for (
int i = 0; i<cutRulLines.size(); i++)
2521 String[] words = cutRulLines.get(i).split(
"\\s+");
2522 String name = words[1];
2523 if (words.length < 6)
2526 +
" Found " + words.length +
" parts inctead of 6."
2527 +
"Check line '" + cutRulLines.get(i) +
"'"
2528 +
"in " + source +
".");
2532 ArrayList<String> opts =
new ArrayList<String>();
2533 if (words.length >= 7)
2535 for (
int wi=6; wi<words.length; wi++)
2537 opts.add(words[wi]);
2541 int priority = Integer.parseInt(words[2]);
2542 if (usedPriorities.contains(priority))
2545 +
" Duplicate priority index " + priority +
". "
2546 +
"Check line '" + cutRulLines.get(i) +
"'"
2547 +
"in " + source +
".");
2549 usedPriorities.add(priority);
2562 Collections.sort(cutRules,
new Comparator<CuttingRule>() {
2584 StringBuilder sb =
new StringBuilder();
2588 sb.append(r.getName()).append(
" ");
2589 sb.append(r.getPriority()).append(
" ");
2590 sb.append(r.getSMARTSAtom0()).append(
" ");
2591 sb.append(r.getSMARTSAtom1()).append(
" ");
2592 sb.append(r.getSMARTSBnd()).append(
" ");
2593 if (r.getOptions()!=
null)
2595 for (String opt : r.getOptions())
2596 sb.append(opt).append(
" ");
2600 writeData(file.getAbsolutePath(), sb.toString(),
false);
2615 PrintWriter pw =
null;
2618 fw =
new FileWriter(f1,
true);
2619 bw =
new BufferedWriter(fw);
2620 pw =
new PrintWriter(bw);
2621 for (File inFile : files)
2624 BufferedReader br =
null;
2627 fr =
new FileReader(inFile);
2628 br =
new BufferedReader(fr);
2630 while ((line = br.readLine()) !=
null)
2658 List<BridgeHeadFindingRule> rules =
null;
2659 BufferedReader br =
null;
2661 br =
new BufferedReader(
new FileReader(fileName));
2664 catch (FileNotFoundException fnfe)
2667 }
catch (IOException ioe)
2678 }
catch (IOException ioe) {
2697 BufferedReader br)
throws IOException
2699 List<BridgeHeadFindingRule> rules =
new ArrayList<>();
2703 rules = reader.fromJson(br,
2704 new TypeToken<ArrayList<BridgeHeadFindingRule>>(){}.getType());
2726 logger.log(Level.ALL,
"ALL");
2727 logger.log(Level.SEVERE,
"SEVERE");
2728 logger.log(Level.WARNING,
"WARN");
2729 logger.log(Level.INFO,
"INFO");
2730 logger.log(Level.CONFIG,
"CONGIF");
2731 logger.log(Level.FINE,
"Fine");
2732 logger.log(Level.FINER,
"FINER");
2733 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.
static void writeGraphsToSDF(File file, List< DGraph > graphs, Logger logger, Randomizer randomizer)
Writes the graphs to SDF file.
static File writeGraphToFile(File file, FileFormat format, DGraph graph)
Writes the a graph to 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 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.