$darkmode
DENOPTIM
MultiMolecularModelBuilder.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.molecularmodeling;
21
22import java.util.ArrayList;
23import java.util.logging.Level;
24import java.util.logging.Logger;
25
26import org.openscience.cdk.interfaces.IAtom;
27import org.openscience.cdk.interfaces.IAtomContainer;
28
29import denoptim.constants.DENOPTIMConstants;
30import denoptim.exception.DENOPTIMException;
31import denoptim.fragspace.FragmentSpaceParameters;
32import denoptim.graph.DGraph;
33import denoptim.graph.rings.RingClosureParameters;
34import denoptim.integration.rcoserver.RCOSocketServerClient;
35import denoptim.integration.tinker.ConformationalSearchPSSROT;
36import denoptim.integration.tinker.TinkerException;
37import denoptim.io.DenoptimIO;
38import denoptim.molecularmodeling.zmatrix.ZMatrix;
39import denoptim.programs.RunTimeParameters.ParametersType;
40import denoptim.programs.moldecularmodelbuilder.MMBuilderParameters;
41import denoptim.utils.AtomOrganizer;
42import denoptim.utils.DummyAtomHandler;
43import denoptim.utils.ObjectPair;
44import denoptim.utils.RotationalSpaceUtils;
45
52{
53 private String molName;
55
57
61 private Logger logger;
62
63//------------------------------------------------------------------------------
64
67 {
68 this.settings = settings;
69 this.logger = settings.getLogger();
70 this.molName = molName;
71 this.molGraph = molGraph;
72 }
73
74//------------------------------------------------------------------------------
75
87 public ArrayList<IAtomContainer> buildMulti3DStructure()
89 {
90 logger.log(Level.INFO, "Building Multiple 3D representations for "
91 + "graph = " + molGraph.toString());
92
93 // Generate XYZ and INT representations
94 long startTime = System.nanoTime();
96 long endTime = System.nanoTime();
97 long time = (endTime - startTime);
98
99 logger.log(Level.FINE, "TIME (build 3D model): " + time/1000000 + " ms"
100 + " #frags: " + mol.getGraph().getVertexList().size()
101 + " #atoms: " + mol.getIAtomContainer().getAtomCount());
102
103 // get settings //TODO: this should happen inside RunTimeParameters
106 {
109 }
110
111 // Evaluate source of isomerism
112 // 1: Attempt Ring Closures
114 ArrayList<ChemicalObjectModel> structures =new ArrayList<ChemicalObjectModel>();
115 boolean skipConfSearch = false;
116 if (rcParams.allowRingClosures() && mol.getGraph().hasOrEmbedsRings())
117 {
118 startTime = System.nanoTime();
119 structures = rct.attemptAllRingClosures(mol);
120 endTime = System.nanoTime();
121 time = (endTime - startTime);
122 int numAllClosedCombs = 0;
123 for (ChemicalObjectModel rcMol : structures)
124 {
125 Object o = rcMol.getIAtomContainer().getProperty(
127 if (o == null)
128 numAllClosedCombs++;
129 }
130 logger.log(Level.FINE, "TIME (close ring): "+time/1000000+" ms"
131 + " #frags: " + mol.getGraph().getVertexList().size()
132 + " #atoms: " + mol.getIAtomContainer().getAtomCount()
133 + " #rcaCombs: " + mol.getRCACombinations().size()
134 + " #allClosedRCSCombs: " + numAllClosedCombs);
135 if (rcParams.requireCompleteRingclosure && numAllClosedCombs<1)
136 {
137 logger.log(Level.INFO, "No fully closed RCA combinaton. "
138 + "Nothing to send to conformational search.");
139 skipConfSearch = true;
140 }
141 // Ring-closing conf search on the RCO server includes general
142 // purpose conformational search, so no need to run a second
143 // conformational search.
144 // RCO server is the default, so the condition checks for non-default
145 // configuration.
146 if (settings.getPSSROTTool() == null)
147 {
148 skipConfSearch = true;
149 }
150 } else {
151 ChemicalObjectModel nMol = mol.deepcopy();
153 structures = new ArrayList<ChemicalObjectModel>();
154 structures.add(nMol);
155 }
156
157 // 2: Conformational search (if possible)
158 if (!skipConfSearch)
159 {
160 if (settings.getPSSROTTool() != null)
161 {
162 try
163 {
164 startTime = System.nanoTime();
167 "cs",
176 time = (endTime - startTime);
177 } catch (TinkerException te)
178 {
179 String msg = "ERROR! Tinker failed on task '"
180 + te.taskName + "'!";
181 if (te.solution != "")
182 {
183 msg = msg + settings.NL + te.solution;
184 }
185 logger.log(Level.SEVERE, msg);
186 throw new DENOPTIMException(msg, te);
187 }
188 } else {
193 for (ChemicalObjectModel com : structures)
194 {
195 try
196 {
198 } catch (Exception e) {
199 e.printStackTrace();
200 String msg = "ERROR! RCOSocketServer failed!";
201 logger.log(Level.SEVERE, msg);
202 throw new DENOPTIMException(msg, e);
203 }
204
205 }
206 }
207 logger.log(Level.FINE, "TIME (conf. search): "+time/1000000+" ms"
208 + " #frags: " + mol.getGraph().getVertexList().size()
209 + " #atoms: " + mol.getIAtomContainer().getAtomCount()
210 + " #rotBnds: " + mol.getRotatableBonds().size());
211 }
212
213 // Convert and return results
214 ArrayList<IAtomContainer> results = new ArrayList<IAtomContainer>();
217 for (ChemicalObjectModel mol3db : structures)
218 {
219 IAtomContainer iac = mol3db.getIAtomContainer();
220
221 IAtomContainer originalOrderMol = AtomOrganizer.makeReorderedCopy(
222 iac, mol3db.getOldToNewOrder(), mol3db.getNewToOldOrder());
223 iac = originalOrderMol;
224
226 {
227 // To keep track of which vertexID should be removed from mol
228 // properties, we remove that property from the mol. It remains
229 // defined in each atom.
230 iac.removeProperty(DENOPTIMConstants.ATMPROPVERTEXID);
231
232 iac = dah.removeDummyInHapto(iac);
233 iac = dah.removeDummy(iac);
234
235 // Now we put the property back among the molecular ones
236 StringBuilder sbMolProp = new StringBuilder();
237 for (IAtom atm : iac.atoms())
238 {
239 sbMolProp.append(" ").append(atm.getProperty(
241 }
242 iac.setProperty(DENOPTIMConstants.ATMPROPVERTEXID,
243 sbMolProp.toString().trim());
244 results.add(iac);
245 } else {
246 results.add(iac);
247 }
248 }
249
250 return results;
251 }
252
253//------------------------------------------------------------------------------
254
264 {
265 // Create 3D tree-like structure
268 IAtomContainer initMol = tb.convertGraphTo3DAtomContainer(molGraph,
269 false, //don't remove used RCAs
270 true, //set the CDK requirements
271 true); //rebuild low-quality structured embedded in templates
272
273 // Reorder atoms and clone molecule.
274 AtomOrganizer oa = new AtomOrganizer();
276 int seedAtm = 0;
277 IAtomContainer reorderedMol = oa.reorderStartingFrom(seedAtm, initMol);
278 ArrayList<Integer> newToOldMap = oa.getNewToOldOrder(seedAtm);
279 ArrayList<Integer> oldToNewMap = oa.getOldToNewOrder(seedAtm);
280 logger.log(Level.FINEST, "oldToNewMap: "+oldToNewMap);
281
282 // Collect rotatable bonds defined by fragment-fragment connections
283 ArrayList<ObjectPair> rotBonds = RotationalSpaceUtils
284 .defineRotatableBonds(reorderedMol,
286 ParametersType.FS_PARAMS)).getRotSpaceDefFile(),
287 true, true, settings.getLogger());
288
289 //Apply constraints, if any
292 ParametersType.FS_PARAMS)).getRotConstraintDefFile(), logger);
293
294 logger.log(Level.FINE, "Rotatable bonds: "+rotBonds);
295 if (logger.isLoggable(Level.FINEST))
296 {
297 logger.log(Level.FINEST, "Reordered IAtomContainer: 'iacToIC.sdf'");
298 DenoptimIO.writeSDFFile("iacToIC.sdf",reorderedMol,false);
299 }
300
301 // Generate Internal Coordinates
302 ZMatrix zmat= ZMatrix.getZMatrixFromIAC(reorderedMol);
303
304 // Generate combined molecular representations (both XYZ and INT)
305 return new ChemicalObjectModel(
306 molGraph,
307 reorderedMol,
308 zmat,
309 molName,
310 rotBonds,
311 oldToNewMap,
312 newToOldMap,
313 logger
314 );
315 }
316
317//------------------------------------------------------------------------------
318
319}
General set of constants used in DENOPTIM.
static final String ATMPROPVERTEXID
String tag of Atom property used to store the unique ID of the Vertex corresponding to the molecular ...
static final String MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
Parameters defining the fragment space.
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:104
List< Vertex > getVertexList()
Returns the list of vertexes without entering Templates.
Definition: DGraph.java:973
boolean hasOrEmbedsRings()
Check for rings in this graph and in any graph that is embedded at any level in any vertex of this gr...
Definition: DGraph.java:1180
Parameters and setting related to handling ring closures.
boolean requireCompleteRingclosure
Flag requesting complete ring closure of all pairs of RCAs in at least one combination of RCAs to con...
Sends the request to produce a socket server running the RingClosingMM service.
static synchronized RCOSocketServerClient getInstance(String hostname, Integer port)
Gets the singleton instance of RCOSocketServerClient.
void setRecordRequestsFileName(String requestFileName)
Sets the pathname to file where to record requests sent to the server.
void runConformationalOptimization(ChemicalObjectModel chemObj, Logger logger)
Runs a conformational optimization using the services provided by the socket server configured for th...
Tool to perform conformational search via Tinker PSSROT program.
static void performPSSROT(ArrayList< ChemicalObjectModel > mols, Map< String, Integer > atmTypeMap, String runLabel, String ffFilePathName, List< String > keyFileLines, List< String > subParamsInit, List< String > subParamsRest, String pssExePathName, String xyzintPathName, String workDir, int taskId, Logger logger)
Performs PSSROT conformational search for all chemical objects in the list.
Exceptions resulting from a failure of Tinker.
String solution
Proposed solution to the failure, or empty string.
Utility methods for input/output.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
Collector of molecular information, related to a single chemical object, that is deployed within the ...
ChemicalObjectModel deepcopy()
Return a new Molecule3DBuilder having exactly the same features of this Molecule3DBuilder.
DGraph getGraph()
Returns the graph representation of this molecule as it was originally generated by DEOPTIM.
List< ObjectPair > getRotatableBonds()
Returns the list of rotatable bonds.
List< Set< ObjectPair > > getRCACombinations()
Returns the list of combinations of RingClosingAttractor.
IAtomContainer getIAtomContainer()
Returns the CDK representation of the molecular system.
MultiMolecularModelBuilder(String molName, DGraph molGraph, MMBuilderParameters settings)
ChemicalObjectModel build3DTree()
Generate 3D structure by assembling 3D fragments according to attachment point vector and following t...
ArrayList< IAtomContainer > buildMulti3DStructure()
Given the graph representation of the molecular constitution, along with the 3D coordinates of the fr...
Toolkit to perform ring closing conformational search.
void saturateRingClosingAttractor(ChemicalObjectModel mol)
Looks for unused RingClosingAttractors and attach proper capping group saturating the free valency/bo...
ArrayList< ChemicalObjectModel > attemptAllRingClosures(ChemicalObjectModel mol)
Performs one or more attempts to close rings by conformational adaptation.
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.
Representation of an atom container's geometry with internal coordinates.
Definition: ZMatrix.java:27
static ZMatrix getZMatrixFromIAC(IAtomContainer mol)
Convert IAtomContainer to ZMatrix.
Definition: ZMatrix.java:545
boolean containsParameters(ParametersType type)
RunTimeParameters getParameters(ParametersType type)
Logger getLogger()
Get the name of the program specific logger.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters for the conformer generator (3D builder).
Tool for re-organizing the list of atoms of an IAtomContainer
ArrayList< Integer > getNewToOldOrder(int seed)
Returns the list of indexes that allow to map the new atom position with the old one.
static IAtomContainer makeReorderedCopy(IAtomContainer original, List< Integer > newToOldOrder, List< Integer > oldToNewOrder)
Produces a new container that looks very similar to the original one, but has a different atom order.
IAtomContainer reorderStartingFrom(int seed, IAtomContainer mol)
Reorder the atoms in mol starting with atom seed
ArrayList< Integer > getOldToNewOrder(int seed)
Returns the list of indexes that allow to map the old atom position with the new one.
Toll to add/remove dummy atoms from linearities or multi-hapto sites.
IAtomContainer removeDummy(IAtomContainer mol)
Removes all dummy atoms and the bonds connecting them to other atoms.
IAtomContainer removeDummyInHapto(IAtomContainer mol)
Tool box for definition and management of the rotational space, which is given by the list of rotatab...
static void processConstrainedRotatableBonds(IAtomContainer mol, ArrayList< ObjectPair > rotatableBonds, String defRotBndContrFile, Logger logger)
Process the constrained rotatable bonds.
static ArrayList< ObjectPair > defineRotatableBonds(IAtomContainer mol, String defRotBndsFile, boolean addIterfragBonds, boolean excludeRings, Logger logger)
Define the rotational space (a.k.a.
FS_PARAMS
Parameters pertaining the definition of the fragment space.
RC_PARAMS
Parameters pertaining to ring closures in graphs.