$darkmode
DENOPTIM
Mol2Graph.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.programs.mol2graph;
20
21import java.io.File;
22import java.util.ArrayList;
23import java.util.List;
24import java.util.logging.Level;
25
26import org.openscience.cdk.interfaces.IAtomContainer;
27
28import denoptim.exception.DENOPTIMException;
29import denoptim.ga.EAUtils;
30import denoptim.graph.DGraph;
31import denoptim.io.DenoptimIO;
32import denoptim.programs.RunTimeParameters.ParametersType;
33import denoptim.programs.fragmenter.FragmenterParameters;
34import denoptim.task.ProgramTask;
35
36
43public class Mol2Graph extends ProgramTask
44{
45
46//------------------------------------------------------------------------------
47
53 public Mol2Graph(File configFile, File workDir)
54 {
55 super(configFile,workDir);
56 }
57
58//------------------------------------------------------------------------------
59
60 @Override
61 public void runProgram() throws Throwable
62 {
64 m2gParams.readParameterFile(configFilePathName.getAbsolutePath());
65 m2gParams.checkParameters();
66 m2gParams.processParameters();
67 m2gParams.startProgramSpecificLogger(loggerIdentifier, false); //to STDOUT
68
71 {
72 frgParams = (FragmenterParameters) m2gParams.getParameters(
74 }
76 {
77 frgParams.setParameters(m2gParams.getParameters(
79 }
80
81 List<DGraph> graphs = new ArrayList<DGraph>();
82 for (int i=0; i<m2gParams.getInputMolsCount(); i++)
83 {
84 IAtomContainer mol = m2gParams.getInputMol(i);
85 DGraph graph = null;
86 try {
87 graph = EAUtils.makeGraphFromFragmentationOfMol(mol, frgParams);
88 } catch (DENOPTIMException de)
89 {
90 m2gParams.getLogger().log(Level.SEVERE, "Unable to convert "
91 + "molecule " + i + " to DENOPTIM graph. "
92 + de.getMessage());
93 return;
94 }
95
96 graphs.add(graph);
97 }
98
99 if (graphs.size()>1)
100 {
101 DenoptimIO.writeGraphsToFile(new File(m2gParams.getOutFile()),
102 m2gParams.getOutFormat(), graphs, m2gParams.getLogger(),
103 m2gParams.getRandomizer());
104 } else {
105 DenoptimIO.writeGraphToFile(new File(m2gParams.getOutFile()),
106 m2gParams.getOutFormat(), graphs.get(0), m2gParams.getLogger(),
107 m2gParams.getRandomizer());
108 }
109 }
110
111//-----------------------------------------------------------------------------
112
113}
Helper methods for the genetic algorithm.
Definition: EAUtils.java:102
static DGraph makeGraphFromFragmentationOfMol(IAtomContainer mol, List< CuttingRule > cuttingRules, Logger logger, ScaffoldingPolicy scaffoldingPolicy)
Converts a molecule into a DGraph by fragmentation and re-assembling of the fragments.
Definition: EAUtils.java:1028
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:104
Utility methods for input/output.
static File writeGraphToFile(File file, FileFormat format, DGraph graph)
Writes the a graph to file.
static File writeGraphsToFile(File file, FileFormat format, List< DGraph > modGraphs, Logger logger, Randomizer randomizer)
Writes the graphs to file.
Logger startProgramSpecificLogger(String loggerIdentifier)
Starts a logger with the given name.
boolean containsParameters(ParametersType type)
void setParameters(RunTimeParameters otherParams)
RunTimeParameters getParameters(ParametersType type)
void readParameterFile(String infile)
Read the parameter TXT file line by line and interpret its content.
Logger getLogger()
Get the name of the program specific logger.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters controlling execution of the fragmenter.
Tool for creating DGraphs from molecules.
Definition: Mol2Graph.java:44
Mol2Graph(File configFile, File workDir)
Creates and configures the program task.
Definition: Mol2Graph.java:53
Parameters controlling execution of GraphEditor.
void processParameters()
Processes all parameters and initialize related objects.
void checkParameters()
Evaluate consistency of input parameters.
Task structure for any of the main programs in the denoptim project, such as genetic algorithm and co...
String loggerIdentifier
Identifier of this program's logger.
File configFilePathName
File containing configuration parameters for the program task.
File workDir
The file system location where we want to be placed when doing the work.
Definition: Task.java:78
FS_PARAMS
Parameters pertaining the definition of the fragment space.
FRG_PARAMS
Parameters controlling the fragmenter.