Skip to content

Commit

Permalink
Update weighted PPPoints for Flexophore. Added automated weight setti…
Browse files Browse the repository at this point in the history
…ngs.
  • Loading branch information
korffmo committed Jul 17, 2024
1 parent 2921328 commit 375065c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,7 @@ else if (includeNodeAtoms) {
public MolDistHistViz createVisualDescriptor(StereoMolecule fragBiggest) {

MolDistHistViz mdhv = null;

recentException = null;

try {
mdhv = creatorMolDistHistViz.create(fragBiggest);
} catch (Exception e) {
Expand All @@ -453,7 +451,6 @@ public MolDistHistViz createVisualDescriptor(StereoMolecule fragBiggest) {
recentException = e;
}
}

return mdhv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class ConstantsFlexophore {



public static final int LABEL_LOW = 0;
public static final int LABEL_NORMAL = 1;
public static final int LABEL_MANDATORY = 2;
public static final int LABEL_WEIGHT_LOW = 0;
public static final int LABEL_WEIGHT_NORMAL = 1;
public static final int LABEL_WEIGHT_MANDATORY = 2;
public static final double VAL_WEIGHT_LOW = 0.5;
public static final double VAL_WEIGHT_NORMAL = 1;
public static final double VAL_WEIGHT_MANDATORY = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static MolDistHistViz create(List<PPNodeVizMultCoord> liPPNodeVizMultCoor
return molDistHistViz;
}


public static void setWeights(MolDistHistViz mdhv, int [] arrWeight){

// The molecule in the descriptor contains the pharmacophore points as additional single atoms.
Expand All @@ -82,18 +81,12 @@ public static void setWeights(MolDistHistViz mdhv, int [] arrWeight){
w[i]=arrWeight[a[i]];
}
int maxWeight = ArrayUtils.max(w);
if(ConstantsFlexophore.LABEL_MANDATORY==maxWeight){
if(ConstantsFlexophore.LABEL_WEIGHT_MANDATORY ==maxWeight){
mdhv.addMandatoryPharmacophorePoint(ppNodeViz.getIndex());
mdhv.setNodeWeight(ppNodeViz.getIndex(), ConstantsFlexophore.VAL_WEIGHT_MANDATORY);
} else if(ConstantsFlexophore.LABEL_LOW==maxWeight){
} else if(ConstantsFlexophore.LABEL_WEIGHT_LOW ==maxWeight){
mdhv.setNodeWeight(ppNodeViz.getIndex(), ConstantsFlexophore.VAL_WEIGHT_LOW);
}

// System.out.println(ArrayUtils.toString(a));
// System.out.println(ArrayUtils.toString(w));
// System.out.println();
//
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class CreatorMolDistHistViz {
private boolean onlyOneConformer;

private Exception recentException = null;

// Calling SSSearcher frequently generates errors.
// private SSSearcher ssSearcher;

Expand Down Expand Up @@ -133,9 +134,7 @@ public void setThreadMaster(ThreadMaster threadMaster) {
}

public MolDistHistViz create(StereoMolecule molOrig) throws Exception {

MolDistHistViz mdhv = null;

switch (conformationMode) {
case CONF_GEN_TS:
mdhv = createMultipleConformations(molOrig, DescriptorHandlerFlexophore.NUM_CONFORMATIONS);
Expand All @@ -148,13 +147,10 @@ public MolDistHistViz create(StereoMolecule molOrig) throws Exception {
break;
default:
throw new RuntimeException("Invalid conformation mode");

}

return mdhv;
}


public Exception getRecentException() {
return recentException;
}
Expand Down Expand Up @@ -184,36 +180,20 @@ public MolDistHistViz createMultipleConformations(StereoMolecule molOrig, int nC
InteractionAtomTypeCalculator.setInteractionTypes(molInPlace);
boolean successfulInitialization = conformerGeneratorStageTries.setMolecule(molInPlace);




if(!successfulInitialization){
return null;
}

//
// Handle carbon atoms connected to hetero atoms
//
List<SubGraphIndices> liSubGraphIndices = subGraphExtractor.extract(molInPlace);
liSubGraphIndices = handleCarbonConnected2Hetero(liSubGraphIndices, molInPlace);
liSubGraphIndices = removeExoCyclicElectronPoorN(liSubGraphIndices, molInPlace);



List<SubGraphIndices> liSubGraphIndices = getSubGraphIndices(molInPlace);

List<MultCoordFragIndex> liMultCoordFragIndex = new ArrayList<>();
for (SubGraphIndices subGraphIndices : liSubGraphIndices) {
liMultCoordFragIndex.add(new MultCoordFragIndex(subGraphIndices.getAtomIndices()));
}



Molecule3D molViz = createConformations(molInPlace, liMultCoordFragIndex, nConformations);

int nPotentialConformers = conformerGeneratorStageTries.getPotentialConformerCount();

onlyOneConformer = false;

if((nPotentialConformers > 1) && (liMultCoordFragIndex.get(0).getCoordinates().size()==1)){

if(DEBUG) {
Expand All @@ -225,57 +205,26 @@ public MolDistHistViz createMultipleConformations(StereoMolecule molOrig, int nC
}
onlyOneConformer = true;
}



MolDistHistViz mdhv = create(liMultCoordFragIndex, molViz);

return mdhv;
}

public List<SubGraphIndices> getSubGraphIndices(Molecule3D molInPlace){
//
// Handle carbon atoms connected to hetero atoms
//
List<SubGraphIndices> liSubGraphIndices = subGraphExtractor.extract(molInPlace);
liSubGraphIndices = handleCarbonConnected2Hetero(liSubGraphIndices, molInPlace);
liSubGraphIndices = removeExoCyclicElectronPoorN(liSubGraphIndices, molInPlace);

return liSubGraphIndices;
}

public int getPotentialConformerCount(){
return conformerGeneratorStageTries.getPotentialConformerCount();
}


/**
* This method must be called before:
* conformerGenerator.initializeConformers(molInPlace, ConformerGenerator.STRATEGY_LIKELY_RANDOM, MAX_NUM_TRIES, false);
*
* Time in nanoseconds for a small molecule with idcode fegPb@JByH@QdbbbarTTbb^bRIRNQsjVZjjjh@J@@@
* 75491600 first conformation
* 16700 sec conformation
* 37200 ...
* 40100 ...
*
* @param molInPlace
* @param liMultCoordFragIndex
* @param nConformations
* @param conformerGenerator
* @return
*/
// public static Molecule3D createConformations(Molecule3D molInPlace, List<MultCoordFragIndex> liMultCoordFragIndex, int nConformations, ConformerGenerator conformerGenerator){
// int nAtoms = molInPlace.getAtoms();
// int ccConformationsGenerated = 0;
// Molecule3D molViz = null;
// for (int i = 0; i < nConformations; i++) {
// boolean conformerGenerated = generateConformerAndSetCoordinates(conformerGenerator, nAtoms, molInPlace);
// if(!conformerGenerated){
// break;
// }
// ccConformationsGenerated++;
// calcFragmentCenter(molInPlace, liMultCoordFragIndex);
// if(i==0){
// molViz = createPharmacophorePoints(molInPlace, liMultCoordFragIndex);
// }
// }
// if(ccConformationsGenerated==0){
// throw new ExceptionConformationGenerationFailed("Impossible to generate one conformer!");
// }
// return molViz;
// }


/**
* This method must be called before:
* initializeConformers(molInPlace);
Expand Down Expand Up @@ -321,8 +270,6 @@ public Molecule3D createConformations(Molecule3D molInPlace, List<MultCoordFragI
throw new ExceptionConformationGenerationFailed("Impossible to generate one conformer!");
}

// System.out.println("ccConformationsGenerated " + ccConformationsGenerated);

return molViz;
}

Expand Down Expand Up @@ -364,9 +311,6 @@ public List<SubGraphIndices> removeExoCyclicElectronPoorN(List<SubGraphIndices>

List<Integer> liElectronPoorN = getElectronPoorN(molInPlace);

// if(liElectronPoorN.size()>0)
// System.out.println("CreatorMolDistHistViz removeExoCyclicElectronPoorN found " + liElectronPoorN.size() + " electron poor atoms in " + molInPlace.getIDCode());

boolean [] arrMatchAtom = new boolean[molInPlace.getAtoms()];

for (int indexAt : liElectronPoorN) {
Expand Down Expand Up @@ -397,9 +341,6 @@ public List<SubGraphIndices> removeExoCyclicElectronPoorN(List<SubGraphIndices>
liSubGraphIndicesProcessed.add(sgiProcessed);
}
return liSubGraphIndicesProcessed;



}

/**
Expand Down Expand Up @@ -485,7 +426,6 @@ public static MolDistHistViz create(List<MultCoordFragIndex> liMultCoordFragInde
public static MolDistHistViz createWithoutCoordinates(List<SubGraphIndices> liMultCoordFragIndex, Molecule3D molecule3D){

MolDistHistViz molDistHistViz = new MolDistHistViz(liMultCoordFragIndex.size(), molecule3D);

List<PPNodeViz> liPPNodeViz = new ArrayList<>();
for (int i = 0; i < liMultCoordFragIndex.size(); i++) {
SubGraphIndices sgi = liMultCoordFragIndex.get(i);
Expand Down Expand Up @@ -513,61 +453,38 @@ public static MolDistHistViz createWithoutCoordinates(List<SubGraphIndices> liMu
molDistHistViz.setDistHist(i,j,arrHistPercent);
}
}

molDistHistViz.realize();

return molDistHistViz;

}

private static Molecule3D createPharmacophorePoints(Molecule3D molecule3D, List<MultCoordFragIndex> liMultCoordFragIndex) {

Molecule3D molCenter = new Molecule3D(molecule3D);

molCenter.ensureHelperArrays(Molecule.cHelperRings);

for (MultCoordFragIndex multCoordFragIndex : liMultCoordFragIndex) {

int [] arrAtomIndexList = multCoordFragIndex.getArrIndexFrag();

// Calculate center coordinates.
Coordinates coordCenter = molCenter.getCenterOfGravity(arrAtomIndexList);

for (int at = 0; at < arrAtomIndexList.length; at++) {

// Atom type.
int interactionType = molCenter.getInteractionAtomType(arrAtomIndexList[at]);

if(interactionType == ConstantsFlexophoreGenerator.INTERACTION_TYPE_NONE){
continue;
}

int iAtomicNo = molCenter.getAtomicNo(arrAtomIndexList[at]);

molCenter.setAtomFlag(arrAtomIndexList[at], Molecule3D.FLAG1, true);

int indexOriginalAtom = arrAtomIndexList[at];

int indexAtm = molCenter.addAtom(iAtomicNo);

molCenter.setInteractionAtomType(indexAtm, interactionType);

String sOrigIndex = Integer.toString(indexOriginalAtom);

molCenter.setAtomChainId(indexAtm, sOrigIndex);

// Set the center coordinates
molCenter.setCoordinates(indexAtm, coordCenter);

molCenter.setAtomFlag(indexAtm, ConstantsFlexophore.FLAG_CENTER_ATOM, true);

molCenter.setPPP(indexAtm, arrAtomIndexList);

}
}

molCenter.ensureHelperArrays(Molecule.cHelperRings);

return molCenter;
}

Expand All @@ -587,37 +504,24 @@ public MolDistHistViz createFromGivenConformation(StereoMolecule molOrig) {

// Just to make sure we will not change something in the original molecule.
Molecule3D molStart = new Molecule3D(molOrig);

molStart.ensureHelperArrays(Molecule.cHelperRings);

InteractionAtomTypeCalculator.setInteractionTypes(molStart);
Molecule3D molInPlace = new Molecule3D(molStart);
molInPlace.ensureHelperArrays(Molecule.cHelperRings);

StereoMolecule molInPlace = new Molecule3D(molStart);
List<SubGraphIndices> liSubGraphIndices = getSubGraphIndices(molInPlace);

molInPlace.ensureHelperArrays(Molecule.cHelperRings);

List<SubGraphIndices> liSubGraphIndices = subGraphExtractor.extract(molInPlace);
liSubGraphIndices = handleCarbonConnected2Hetero(liSubGraphIndices, molInPlace);

List<MultCoordFragIndex> liMultCoordFragIndex = new ArrayList<>();
for (SubGraphIndices subGraphIndices : liSubGraphIndices) {
liMultCoordFragIndex.add(new MultCoordFragIndex(subGraphIndices.getAtomIndices()));
}

calcFragmentCenter(molStart, liMultCoordFragIndex);

MolDistHistViz mdhv = create(liMultCoordFragIndex, molStart);

return mdhv;
}

/**
* @param nAtoms
* @param molInPlace
* @return
*/


/**
* Calculates the center of the fragments and stores the coordinates in MultCoordFragIndex.
* @param molecule3D
Expand All @@ -626,9 +530,7 @@ public MolDistHistViz createFromGivenConformation(StereoMolecule molOrig) {
public static void calcFragmentCenter(Molecule3D molecule3D, List<MultCoordFragIndex> liMultCoordFragIndex) {

for (MultCoordFragIndex multCoordFragIndex : liMultCoordFragIndex) {

int [] arrAtomIndexList = multCoordFragIndex.getArrIndexFrag();

// Calculate center coordinates.
Coordinates coordCenter = molecule3D.getCenterOfGravity(arrAtomIndexList);
multCoordFragIndex.addCoord(coordCenter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,17 @@ public List<SubGraphIndices> extract(StereoMolecule molOrig) {
}
}



List<SubGraphIndices> liFragment = new ArrayList<>();

//
// End standing hetero atom groups
//
List<SubGraphIndices> liFragmentHetero = getEndStandingHeteroGroups(mol, liEndStandingAtoms);



liFragment.addAll(liFragmentHetero);
HashSetInt hsAtomIndicesInFragment = new HashSetInt();
SubGraphIndices.addAtomIndices(hsAtomIndicesInFragment, liFragmentHetero);



//
// Small rings
//
Expand All @@ -145,7 +139,6 @@ public List<SubGraphIndices> extract(StereoMolecule molOrig) {
SubGraphIndices.addAtomIndices(hsAtomIndicesInSmallRings, liFragmentRings);
hsAtomIndicesInFragment.add(hsAtomIndicesInSmallRings.getValues());


//
// Remaining hetero atoms
// Hetero atoms that were not covered by the end standing groups and that are not enclosed in the small rings.
Expand Down
Loading

0 comments on commit 375065c

Please sign in to comment.