Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
thsa committed Apr 5, 2024
2 parents f9ced29 + 0cda76e commit 484e1c6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 51 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Please follow the naming scheme YEAR.MONTH.RELEASE_NO_OF_MONTH
(eg. 2016.4.1 for second release in Apr 2016)
-->
<version>2024.3.2-SNAPSHOT</version>
<version>2024.3.3-SNAPSHOT</version>

<name>OpenChemLib</name>
<description>Open Source Chemistry Library</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static MolDistHist assembleNoDistHist (MolDistHist ... arr){
mdh.addNode(arr[i].getNode(j));
}
}

return mdh;
}
public static boolean isZero(byte [] b){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static PPNodeViz createWithoutCoordinates(SubGraphIndices sgi, int indexP
ppNodeViz.add(interactionType);
ppNodeViz.addIndexOriginalAtom(index);
}
ppNodeViz.realize();
return ppNodeViz;
}
public static List<PPNodeViz> createWithoutCoordinates(List<SubGraphIndices> liSubGraphIndices, Molecule3D mol){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ObjectiveBlurFlexophoreHardMatchUncovered implements IObjectiveComp

private static final float INIT_VAL = -1;


private boolean modeQuery;

private int marginQuery;
Expand All @@ -61,6 +60,7 @@ public class ObjectiveBlurFlexophoreHardMatchUncovered implements IObjectiveComp

private int nodesQuery;


private byte [] arrTmpHist;

private boolean validHelpersQuery;
Expand Down Expand Up @@ -286,29 +286,31 @@ public boolean isValidSolution(SolutionCompleteGraph solution) {
//
// Check for one hetero atom in solution.
// Not checked for fragment mapping!
if(!fragmentNodesMapping && mapping){

if (!fragmentNodesMapping && mapping) {
boolean heteroNodeQuery = false;
boolean heteroNodeBase = false;
for (int i = 0; i < heap; i++) {
int indexNodeQuery = solution.getIndexQueryFromHeap(i);
PPNode nodeQuery = mdhvQueryBlurredHist.getNode(indexNodeQuery);
if(nodeQuery.hasHeteroAtom()){
if (nodeQuery.hasHeteroAtom()) {
heteroNodeQuery = true;
}
int indexNodeBase = solution.getIndexCorrespondingBaseNode(indexNodeQuery);
PPNode nodeBase = mdhvBaseBlurredHist.getNode(indexNodeBase);
if(nodeBase.hasHeteroAtom()){
if (nodeBase.hasHeteroAtom()) {
heteroNodeBase = true;
}
if(heteroNodeQuery && heteroNodeBase){
if (heteroNodeQuery && heteroNodeBase) {
break;
}
}
if(!heteroNodeQuery || !heteroNodeBase) {
if (!heteroNodeQuery || !heteroNodeBase) {
mapping = false;
}
}


//
// Check for matching nodes.
//
Expand Down Expand Up @@ -540,6 +542,64 @@ public float getSimilarity(SolutionCompleteGraph solution) {
// For testing
// return (float)1.0;

}
public float getSimilarityHistograms(SolutionCompleteGraph solution) {

long t0 = System.nanoTime();

if(!validHelpersQuery){
calculateHelpersQuery();
}

if(!validHelpersBase){
calculateHelpersBase();
}

if(resetSimilarityArrays){
resetSimilarityMatrices();
}

int heap = solution.getSizeHeap();

//
// the query must hit with all pharmacophore nodes
//
if(modeQuery) {
if (nodesQuery != heap) {
similarity=0;
return (float)similarity;
}
}

double sumSimDistHist = 0;

for (int i = 0; i < heap; i++) {

int indexNode1Query = solution.getIndexQueryFromHeap(i);

int indexNode1Base = solution.getIndexCorrespondingBaseNode(indexNode1Query);

for (int j = i+1; j < heap; j++) {
int indexNode2Query = solution.getIndexQueryFromHeap(j);

int indexNode2Base = solution.getIndexCorrespondingBaseNode(indexNode2Query);

double simDistHist = getSimilarityHistogram(indexNode1Query, indexNode2Query, indexNode1Base, indexNode2Base);

sumSimDistHist += simDistHist;

if(verbose) {
System.out.println("scorePairwiseMapping " + Formatter.format2(simDistHist));
}
}
}

double mappings = ((heap * heap)-heap) / 2.0;

float simDistHistAvr = (float)(sumSimDistHist/mappings);

return simDistHistAvr;

}
public float getSimilarityNodes(SolutionCompleteGraph solution) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,28 @@ public List<SubGraphIndices> extract(StereoMolecule molOrig) {
}
}
if(ccConnNonHydrogen==1){
liEndStandingAtoms.add(i);
if(mol.getAtomicNo(i)>1)
liEndStandingAtoms.add(i);
}
}



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 @@ -137,19 +145,20 @@ 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.
//
List<SubGraphIndices> liFragmentRemainingHetero = getRemainingHeteroGroups(mol, hsAtomIndicesInFragment);

liFragment.addAll(liFragmentRemainingHetero);

SubGraphIndices.addAtomIndices(hsAtomIndicesInFragment, liFragmentRemainingHetero);

//
// End standing aliphatic group
//

List<SubGraphIndices> liFragmentEndStandingAliphaticGroup = getEndStandingAliphaticGroups(mol, liEndStandingAtoms, hsAtomIndicesInFragment);

liFragment.addAll(liFragmentEndStandingAliphaticGroup);
Expand Down Expand Up @@ -654,6 +663,7 @@ private List<SubGraphIndices> getEndStandingAliphaticGroups(StereoMolecule mol,
//

for (int indexEndStandingAtom : liEndStandingAtoms) {

if(arrAtomIndicesUsedMap[indexEndStandingAtom]){
continue;
}
Expand Down Expand Up @@ -690,9 +700,6 @@ private List<SubGraphIndices> getEndStandingAliphaticGroups(StereoMolecule mol,
fragment.addIndex(indexEndStandingAtom);
liFragmentEndStandingAliphaticGroup.add(fragment);
}



}

//
Expand Down Expand Up @@ -743,59 +750,41 @@ private void broadFirstForNonRingCarbon(StereoMolecule mol, SubGraphIndices frag
int [] arrAtomIndicesUsed = hsAtomIndicesUsed.getValues();

for (int indexAtmUsed : arrAtomIndicesUsed) {

arrAtomIndicesUsedMap[indexAtmUsed] = true;

}

LinkedList<Integer> liIndAtm = new LinkedList<>();

int [] arrIndAtmLayer = new int[atoms];

// Contains only one index.
int [] arrIndAtm = fragment.getAtomIndices();

for (int indAtm : arrIndAtm) {
liIndAtm.add(indAtm);
arrIndAtmLayer[indAtm] = 0;
}

while (!liIndAtm.isEmpty()){

int indAtm = liIndAtm.poll();

if(arrIndAtmLayer[indAtm]>maxDepth){

continue;

}

fragment.addIndex(indAtm);

int nConnAtms = mol.getConnAtoms(indAtm);

for (int i = 0; i < nConnAtms; i++) {

int indAtmConn = mol.getConnAtom(indAtm, i);

if(arrAtomIndicesUsedMap[indAtmConn]){

continue;

}

if(arrAtomInSmallRing[indAtmConn]) {

continue;

}

if(mol.getAtomicNo(indAtmConn)==6) {

liIndAtm.add(indAtmConn);

arrIndAtmLayer[indAtmConn] = arrIndAtmLayer[indAtm] + 1;

}
}
}
Expand Down Expand Up @@ -999,23 +988,14 @@ private boolean isSmallRingAtom(int indexAtom){
private List<SubGraphIndices> getSmallRingsWithConnEndStanding(StereoMolecule mol){

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



RingHelper ringHelper = new RingHelper(mol);

RingCollection ringCollection = ringHelper.getRingCollection();

int rings = ringCollection.getSize();

for (int ringNo = 0; ringNo < rings; ringNo++) {

int ringSize = ringCollection.getRingSize(ringNo);

if(ringSize > MAX_RING_SIZE_TO_SUMMARIZE_HETERO_RINGS) {
continue;
}

int [] arrIndexRingAtoms = ringCollection.getRingAtoms(ringNo);

// Exclude enclosing rings
Expand All @@ -1024,9 +1004,7 @@ private List<SubGraphIndices> getSmallRingsWithConnEndStanding(StereoMolecule mo
}

SubGraphIndices fragment = new SubGraphIndices();

fragment.addIndex(arrIndexRingAtoms);

liFragmentRings.add(fragment);
}

Expand All @@ -1039,23 +1017,21 @@ private List<SubGraphIndices> getSmallRingsWithConnEndStanding(StereoMolecule mo
int [] arrIndexRingAtoms = subGraphIndices.getAtomIndices();

for (int indexRingAtom : arrIndexRingAtoms) {

int nConnAtms = mol.getConnAtoms(indexRingAtom);

if(nConnAtms < 3) {
continue;
}

for (int i = 0; i < nConnAtms; i++) {

int indAtmConn = mol.getConnAtom(indexRingAtom, i);

int nConnAtomsChild = mol.getConnAtoms(indAtmConn);
if(mol.getAtomicNo(indAtmConn)==1){ // explicit H or D
continue;
}

int nConnAtomsChild = mol.getConnAtoms(indAtmConn);
if(nConnAtomsChild == 1){

subGraphIndices.addIndex(indAtmConn);

}
}
}
Expand Down Expand Up @@ -1228,6 +1204,7 @@ private List<SubGraphIndices> getEndStandingHeteroGroups(StereoMolecule mol, Lis
}
}


SubGraphIndices.merge(liFragmentHetero);

//
Expand Down Expand Up @@ -1272,6 +1249,8 @@ private List<SubGraphIndices> getEndStandingHeteroGroups(StereoMolecule mol, Lis

SubGraphIndices.merge(liFragmentHetero);



//
// Get fourth layer
// Only if the new atom is a hetero atom.
Expand Down Expand Up @@ -1300,6 +1279,7 @@ private List<SubGraphIndices> getEndStandingHeteroGroups(StereoMolecule mol, Lis

SubGraphIndices.merge(liFragmentHetero);


//
// Add end standing attached carbon atoms to the group.
//
Expand All @@ -1322,10 +1302,13 @@ private List<SubGraphIndices> getEndStandingHeteroGroups(StereoMolecule mol, Lis
continue;
}

frag.addIndex(indexAtmConn);
if((mol.getAtomicNo(indexAtmConn) != 6) && (mol.getAtomicNo(indexAtmConn) != 1)) { // explicit H (Deuterium made trouble)
System.err.println("Wrong non-carbon atom at this index " + indexAtmConn);
throw new RuntimeException("This should not happen! But happened for " + mol.getIDCode());

if(mol.getAtomicNo(indexAtmConn) != 1) { // explicit H (Deuterium made trouble)
frag.addIndex(indexAtmConn);
if (mol.getAtomicNo(indexAtmConn) != 6) {
System.err.println("Wrong non-carbon atom at this index " + indexAtmConn);
throw new RuntimeException("This should not happen! But happened for " + mol.getIDCode());
}
}
}
}
Expand Down

0 comments on commit 484e1c6

Please sign in to comment.