Skip to content

Commit

Permalink
Added timeout for conformation calculations in Flexophore
Browse files Browse the repository at this point in the history
  • Loading branch information
korffmo committed Feb 19, 2024
1 parent 7e8a01d commit a00cb43
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
import com.actelion.research.chem.descriptor.flexophore.redgraph.SubGraphExtractor;
import com.actelion.research.chem.descriptor.flexophore.redgraph.SubGraphIndices;
import com.actelion.research.chem.interactionstatistics.InteractionAtomTypeCalculator;
import com.actelion.research.util.TimeDelta;
import org.openmolecules.chem.conf.gen.ConformerGenerator;
import org.openmolecules.chem.conf.gen.RigidFragmentCache;

import java.util.*;
import java.util.concurrent.TimeoutException;

/**
* CreatorMolDistHistViz
Expand All @@ -57,6 +59,18 @@ public class CreatorMolDistHistViz {

public static final long SEED = 123456789;

/**
* Similarity 0.977, similarity for identical molecule and a timeout of 5 min. So timeout of 6 min should be fine.
*
CreatorMolDistHistViz: ExceptionTimeOutConformerGeneration for idcode enY\JH@@amaNe`ZPICHhdhThdleEEEDhYThddZFKGLRX@J`@jjiijjZjAPbbT@@, hence generated 8 conformers.
5 Minutes 52 Seconds 79 Millisec
CreatorMolDistHistViz: ExceptionTimeOutConformerGeneration for idcode enY\JH@@amaNe`ZPICHhdhThdleEEEDhYThddZFKGLRX@J`@jjiijjZjAPbRR@@, hence generated 25 conformers.
* 5 Minutes 52 Seconds 79 Millisec
* [(390*2) (391) (392) (4358*6) (9,4358*6) (4358*4,4488) (590088,598407) (590088,598407)]
*/
public static final long TIMEOUT_CONFORMER_CALCULATION_MS = TimeDelta.MS_MINUTE * 6;
// public static final long TIMEOUT_CONFORMER_CALCULATION_MS = TimeDelta.MS_SECOND * 30;

// Maximum number of tries to generate conformers with the torsion rule based conformer generator from Thomas Sander
private static final int MAX_TRIES_CONFORMERS = 10;
private static final int MAX_INITIALIZATION_STAGE = 5;
Expand All @@ -65,7 +79,6 @@ public class CreatorMolDistHistViz {
private static final int MAX_NUM_ATOMS = 1000;

private static final int CONF_GEN_TS = 0;

public static final int CONF_GIVEN_SINGLE_CONFORMATION = 1;
public static final int SINGLE_CONFORMATION = 2;

Expand All @@ -81,6 +94,7 @@ public class CreatorMolDistHistViz {
private int conformationMode;

private long seed;
private long t0ConformerCalcStarted;

// for debugging
private boolean onlyOneConformer;
Expand All @@ -89,6 +103,8 @@ public class CreatorMolDistHistViz {

private int [] arrIndexAtomNewTmp;

private long timeoutConformerCalculationMS;

public CreatorMolDistHistViz() {

seed = SEED;
Expand All @@ -104,6 +120,8 @@ public CreatorMolDistHistViz() {

initializationStage = 0;

t0ConformerCalcStarted = 0;

// System.out.println("CreatorCompleteGraph conformationMode " + conformationMode);

}
Expand Down Expand Up @@ -145,6 +163,10 @@ public ConformerGenerator getConformerGenerator(){
public void resetInitializationStage(){
initializationStage=0;
}

/**
* do not forget to call initializeConformers(mol) after!
*/
public void incrementInitializationStage(){
initializationStage++;
if(initializationStage>MAX_INITIALIZATION_STAGE){
Expand Down Expand Up @@ -217,7 +239,8 @@ public boolean initializeConformers(Molecule3D molInPlace){

}

if(!successfulInitialization && exception!=null){
if(!successfulInitialization){
System.err.println("CreatorMolDistHistViz initializeConformers(...) failed for " + molInPlace.getIDCode());
recentException = exception;
}

Expand Down Expand Up @@ -346,7 +369,7 @@ public int getPotentialConformerCount(){

/**
* This method must be called before:
* conformerGenerator.initializeConformers(molInPlace, ConformerGenerator.STRATEGY_LIKELY_RANDOM, MAX_NUM_TRIES, false);
* initializeConformers(molInPlace);
*
* Time in nanoseconds for a small molecule with idcode fegPb@JByH@QdbbbarTTbb^bRIRNQsjVZjjjh@J@@@
* 75491600 first conformation
Expand All @@ -363,8 +386,18 @@ public Molecule3D createConformations(Molecule3D molInPlace, List<MultCoordFragI
int nAtoms = molInPlace.getAtoms();
int ccConformationsGenerated = 0;
Molecule3D molViz = null;

t0ConformerCalcStarted = System.currentTimeMillis();
for (int i = 0; i < nConformations; i++) {
boolean conformerGenerated = generateConformerAndSetCoordinates(nAtoms, molInPlace);
boolean conformerGenerated = false;
try {
conformerGenerated = generateConformerAndSetCoordinates(nAtoms, molInPlace);
} catch (ExceptionTimeOutConformerGeneration e) {
System.err.println(
"CreatorMolDistHistViz: ExceptionTimeOutConformerGeneration for idcode " + molInPlace.getIDCode( )+ ", hence generated " + ccConformationsGenerated + " conformers.");
// e.printStackTrace();
break;
}

if(!conformerGenerated){
break;
Expand All @@ -375,6 +408,7 @@ public Molecule3D createConformations(Molecule3D molInPlace, List<MultCoordFragI
molViz = createPharmacophorePoints(molInPlace, liMultCoordFragIndex);
}
}

if(ccConformationsGenerated==0){
throw new ExceptionConformationGenerationFailed("Impossible to generate one conformer!");
}
Expand Down Expand Up @@ -547,6 +581,9 @@ private static Molecule3D createPharmacophorePoints(Molecule3D molecule3D, List<
return molCenter;
}

/**
* Do not forget to call initializeConformers(molInPlace) after!
*/
public void injectNewSeed(){
seed = new Date().getTime();
conformerGenerator = new ConformerGenerator(seed, false);
Expand Down Expand Up @@ -606,11 +643,20 @@ public boolean generateConformerAndSetCoordinates(int nAtoms, Molecule3D molInPl
conformer = conformerGenerator.getNextConformer();
if (conformer == null) {
injectNewSeed();
initializeConformers(molInPlace);
}
ccTries++;
if (ccTries == MAX_TRIES_CONFORMERS) {
break;
}

if(t0ConformerCalcStarted>0) {
long t1 = System.currentTimeMillis();
long d = t1 - t0ConformerCalcStarted;
if(d>TIMEOUT_CONFORMER_CALCULATION_MS) {
throw new ExceptionTimeOutConformerGeneration();
}
}
}

if(conformer==null && canIncrementInitializationStage()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.actelion.research.chem.descriptor.flexophore.generator;

/*
Copyright (c) 2024 Alipheron AG. All rights reserved.
This file is part of the Alipheron AG software suite.
Licensed under the Alipheron AG Software License Agreement (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at the company's official website or upon request.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Created by Modest von Korff
19/02/2024
*/
public class ExceptionTimeOutConformerGeneration extends RuntimeException{



}

0 comments on commit a00cb43

Please sign in to comment.