diff --git a/src/main/java/com/actelion/research/chem/descriptor/DescriptorHandlerFlexophore.java b/src/main/java/com/actelion/research/chem/descriptor/DescriptorHandlerFlexophore.java index d03dd1b5..5a70bdef 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/DescriptorHandlerFlexophore.java +++ b/src/main/java/com/actelion/research/chem/descriptor/DescriptorHandlerFlexophore.java @@ -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) { @@ -453,7 +451,6 @@ public MolDistHistViz createVisualDescriptor(StereoMolecule fragBiggest) { recentException = e; } } - return mdhv; } diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/ConstantsFlexophore.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/ConstantsFlexophore.java index bc360549..b98c16ba 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/ConstantsFlexophore.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/ConstantsFlexophore.java @@ -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; diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java index c4aa799e..8fe0c283 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java @@ -63,7 +63,6 @@ public static MolDistHistViz create(List liPPNodeVizMultCoor return molDistHistViz; } - public static void setWeights(MolDistHistViz mdhv, int [] arrWeight){ // The molecule in the descriptor contains the pharmacophore points as additional single atoms. @@ -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(); -// } - } } diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/CreatorMolDistHistViz.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/CreatorMolDistHistViz.java index 684d3c9c..20de124a 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/CreatorMolDistHistViz.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/CreatorMolDistHistViz.java @@ -102,6 +102,7 @@ public class CreatorMolDistHistViz { private boolean onlyOneConformer; private Exception recentException = null; + // Calling SSSearcher frequently generates errors. // private SSSearcher ssSearcher; @@ -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); @@ -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; } @@ -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 liSubGraphIndices = subGraphExtractor.extract(molInPlace); - liSubGraphIndices = handleCarbonConnected2Hetero(liSubGraphIndices, molInPlace); - liSubGraphIndices = removeExoCyclicElectronPoorN(liSubGraphIndices, molInPlace); - - - + List liSubGraphIndices = getSubGraphIndices(molInPlace); List 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) { @@ -225,57 +205,26 @@ public MolDistHistViz createMultipleConformations(StereoMolecule molOrig, int nC } onlyOneConformer = true; } - - - MolDistHistViz mdhv = create(liMultCoordFragIndex, molViz); - return mdhv; } + public List getSubGraphIndices(Molecule3D molInPlace){ + // + // Handle carbon atoms connected to hetero atoms + // + List 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 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); @@ -321,8 +270,6 @@ public Molecule3D createConformations(Molecule3D molInPlace, List removeExoCyclicElectronPoorN(List List 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) { @@ -397,9 +341,6 @@ public List removeExoCyclicElectronPoorN(List liSubGraphIndicesProcessed.add(sgiProcessed); } return liSubGraphIndicesProcessed; - - - } /** @@ -485,7 +426,6 @@ public static MolDistHistViz create(List liMultCoordFragInde public static MolDistHistViz createWithoutCoordinates(List liMultCoordFragIndex, Molecule3D molecule3D){ MolDistHistViz molDistHistViz = new MolDistHistViz(liMultCoordFragIndex.size(), molecule3D); - List liPPNodeViz = new ArrayList<>(); for (int i = 0; i < liMultCoordFragIndex.size(); i++) { SubGraphIndices sgi = liMultCoordFragIndex.get(i); @@ -513,61 +453,38 @@ public static MolDistHistViz createWithoutCoordinates(List liMu molDistHistViz.setDistHist(i,j,arrHistPercent); } } - molDistHistViz.realize(); - return molDistHistViz; - } private static Molecule3D createPharmacophorePoints(Molecule3D molecule3D, List 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; } @@ -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 liSubGraphIndices = getSubGraphIndices(molInPlace); - molInPlace.ensureHelperArrays(Molecule.cHelperRings); - List liSubGraphIndices = subGraphExtractor.extract(molInPlace); - liSubGraphIndices = handleCarbonConnected2Hetero(liSubGraphIndices, molInPlace); List 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 @@ -626,9 +530,7 @@ public MolDistHistViz createFromGivenConformation(StereoMolecule molOrig) { public static void calcFragmentCenter(Molecule3D molecule3D, List liMultCoordFragIndex) { for (MultCoordFragIndex multCoordFragIndex : liMultCoordFragIndex) { - int [] arrAtomIndexList = multCoordFragIndex.getArrIndexFrag(); - // Calculate center coordinates. Coordinates coordCenter = molecule3D.getCenterOfGravity(arrAtomIndexList); multCoordFragIndex.addCoord(coordCenter); diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphExtractor.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphExtractor.java index b1dbf486..70855507 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphExtractor.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphExtractor.java @@ -119,8 +119,6 @@ public List extract(StereoMolecule molOrig) { } } - - List liFragment = new ArrayList<>(); // @@ -128,14 +126,10 @@ public List extract(StereoMolecule molOrig) { // List liFragmentHetero = getEndStandingHeteroGroups(mol, liEndStandingAtoms); - - liFragment.addAll(liFragmentHetero); HashSetInt hsAtomIndicesInFragment = new HashSetInt(); SubGraphIndices.addAtomIndices(hsAtomIndicesInFragment, liFragmentHetero); - - // // Small rings // @@ -145,7 +139,6 @@ public List 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. diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphIndices.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphIndices.java index a760ec3f..8a17382c 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphIndices.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphIndices.java @@ -34,12 +34,11 @@ package com.actelion.research.chem.descriptor.flexophore.redgraph; +import com.actelion.research.chem.ExtendedMoleculeFunctions; +import com.actelion.research.chem.StereoMolecule; import com.actelion.research.util.hash.HashSetInt; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; /** * SubGraphIndices @@ -55,8 +54,6 @@ public class SubGraphIndices { private HashSetInt hsIndexAtom; - - public SubGraphIndices() { hsIndexAtom = new HashSetInt(); } @@ -179,6 +176,18 @@ public String toString() { return sb.toString(); } + + public static boolean isOnlyCarbon(StereoMolecule mol, SubGraphIndices sgi){ + boolean carbon=true; + for (int atomIndex : sgi.getAtomIndices()) { + if(mol.getAtomicNo(atomIndex)!=6){ + carbon=false; + break; + } + } + return carbon; + } + /** * Merges fragments containing a common atom index. The fragments in the list are merged and the list is * shrinked. @@ -216,7 +225,6 @@ public static List mergeOverlapping(List liFra SubGraphIndices frag1 = liFragment.get(i); OverlappingFragments overlappingFragments = new OverlappingFragments(frag1); liOverlappingFragments.add(overlappingFragments); - } boolean merged = true; @@ -253,6 +261,64 @@ protected static void addAtomIndices(HashSetInt hs, List liFrag } } + /** + * + * @param mol + * @param liSGI + * @param indexSGI index for the {@link SubGraphIndices} undr consideration. + * @return true if the {@link SubGraphIndices} under consideration connects two or more other {@link SubGraphIndices}. + */ + public static boolean isLinker(StereoMolecule mol, List liSGI, int indexSGI){ + + int atoms = mol.getAtoms(); + + SubGraphIndices sgi = liSGI.get(indexSGI); + + boolean [] arrAtomIndicesUsedMap = new boolean[atoms]; + + for (int indexAtmUsed : sgi.getAtomIndices()) { + arrAtomIndicesUsedMap[indexAtmUsed] = true; + } + + boolean [] mapSGI = new boolean[liSGI.size()]; + + for (int indAtmStart : sgi.getAtomIndices()) { + LinkedList liIndAtm = new LinkedList<>(); + liIndAtm.add(indAtmStart); + + out: + while (!liIndAtm.isEmpty()) { + int indAtm = liIndAtm.poll(); + int nConnAtms = mol.getConnAtoms(indAtm); + for (int i = 0; i < nConnAtms; i++) { + int indAtmConn = mol.getConnAtom(indAtm, i); + if (arrAtomIndicesUsedMap[indAtmConn]) { + continue; + } + arrAtomIndicesUsedMap[indAtmConn] = true; + // Is in neighbour sgi? + for (int j = 0; j < liSGI.size(); j++) { + if(indexSGI==j) + continue; + SubGraphIndices sgi2Check = liSGI.get(j); + if(sgi2Check.contains(indAtmConn)){ + mapSGI[j]=true; + break out; + } + } + liIndAtm.add(indAtmConn); + } + } + } + + int ccLinked=0; + for (boolean b : mapSGI) { + if(b)ccLinked++; + } + return (ccLinked>1); + } + + public static Comparator getComparatorNumIndices() { return new Comparator() { diff --git a/src/main/java/com/actelion/research/util/StringFunctions.java b/src/main/java/com/actelion/research/util/StringFunctions.java index c71237c1..7b46fd9c 100644 --- a/src/main/java/com/actelion/research/util/StringFunctions.java +++ b/src/main/java/com/actelion/research/util/StringFunctions.java @@ -346,12 +346,9 @@ public static String getMaximumOverlap(List li, int minsize){ String maxo = ""; List liPat = getAllSubStrings(li.get(0), minsize); - for (int i = 0; i < liPat.size(); i++) { String pat = liPat.get(i); - Pattern p = Pattern.compile(pat); - boolean match=true; for (int j = 1; j < li.size(); j++) { String line = li.get(j); @@ -519,9 +516,6 @@ public static String format(String str, char replacement) { cLastLetter = replacement; } } - - - return sb.toString(); } @@ -535,13 +529,10 @@ public static String format(String str, char replacement) { */ public static String getString(String sLine, String sStart, String sEnd) { String str = ""; - int iStart = sLine.indexOf(sStart) + sStart.length(); int iEnd = sLine.indexOf(sEnd); - if (iStart > -1 && iEnd > -1) str = sLine.substring(iStart, iEnd); - return str; } @@ -554,12 +545,9 @@ public static String getString(String sLine, String sStart, String sEnd) { public static String getStringFromRegEx(String str, String regex) { Pattern pa = Pattern.compile(regex); - Matcher ma = pa.matcher(str); - int start = -1; int end = -1; - if(ma.find()){ MatchResult mr = ma.toMatchResult(); start = mr.start(); @@ -572,14 +560,10 @@ public static String getStringFromRegEx(String str, String regex) { } public static Point getStartEnd(String str, String regex) { - Pattern pa = Pattern.compile(regex); - Matcher ma = pa.matcher(str); - int start = -1; int end = -1; - if(ma.find()){ MatchResult mr = ma.toMatchResult(); start = mr.start(); @@ -587,17 +571,13 @@ public static Point getStartEnd(String str, String regex) { } else { return null; } - return new Point(start,end); } public static boolean isRegexInString(String str, String regex) { - Pattern pa = Pattern.compile(regex); - Matcher ma = pa.matcher(str); - if(ma.find()){ return true; } else { @@ -612,20 +592,13 @@ public static boolean isRegexInString(String str, String regex) { * @return expression which was matched by regex. */ public static String extract(String str, String regex) { - String substring = ""; - Pattern pa = Pattern.compile(regex); - Matcher ma = pa.matcher(str); - if(ma.find()) { - MatchResult mr = ma.toMatchResult(); - substring = mr.group(); } - return substring; } @@ -638,26 +611,16 @@ public static String extract(String str, String regex) { public static String extractInverse(String str, String regex) { String substring = ""; - Pattern pa = Pattern.compile(regex); - Matcher ma = pa.matcher(str); - if(ma.find()) { - MatchResult mr = ma.toMatchResult(); - int start = mr.start(); - int end = mr.end(); - String rest1 = str.substring(0, start); - String rest2 = str.substring(end); - substring = rest1 + rest2; } - return substring; } @@ -1055,18 +1018,12 @@ public static String toString(String [] arr, String seperator){ } public static String toString(int [] arr, String seperator){ - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < arr.length; i++) { - if(sb.length()>0) sb.append(seperator); - sb.append(Integer.toString(arr[i])); - } - return sb.toString(); } @@ -1076,25 +1033,18 @@ public static String toString(int [] arr, String seperator){ * @return */ public static String toStringTabNL(String [][] arr){ - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < arr.length; i++) { - for (int j = 0; j < arr[i].length; j++) { sb.append(arr[i][j]); - if(j li, String sep) { public static String toStringLong(List li, String sep) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < li.size(); i++) { sb.append(li.get(i)); - if(i < li.size()-1){ sb.append(sep); } } - return sb.toString(); } public static String toStringInt(List li, String sep) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < li.size(); i++) { sb.append(li.get(i)); - if(i < li.size()-1){ sb.append(sep); } } - return sb.toString(); } public static String toStringInt(List li) { @@ -1160,13 +1103,10 @@ public static String toStringInt(List li) { public static String toSortedString(List li) { StringBuilder sb = new StringBuilder(); - Collections.sort(li); - for (String s : li) { sb.append(s); } - return sb.toString(); }