Skip to content

Commit

Permalink
Implemented handling of ring closures
Browse files Browse the repository at this point in the history
  • Loading branch information
ntk73 authored and johnmay committed Oct 6, 2016
1 parent 2a8e5b1 commit 080f776
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,20 +545,6 @@ public String getFPSmarts(FP fp, IAtomContainer molecule)
if (n == 0)
return null;

/*
//This is temporary code
if (n==1)
{
StringBuffer sb = new StringBuffer();
sb.append(getAtomSmarts(molecule, fp.atoms[0]));
//Handle "external" neighbors if needed
//TODO
return sb.toString();
}
*/

curFP = fp;
curFPMolecule = molecule;

Expand All @@ -575,7 +561,7 @@ public String getFPSmarts(FP fp, IAtomContainer molecule)
traversedAtoms.add(node.atom);
nodes.put(node.atom, node);

return nodeToString(fp.atoms[0]);
return nodeToString(fp.atoms[0]); //traverse recursively all atoms
}


Expand Down Expand Up @@ -621,16 +607,24 @@ String nodeToString(int atom)
}
else
{
// Handle ring closure: adding indexes to both atoms
//TODO
// Handle ring closure: adding indexes to both atoms

if (!ringClosures.contains(neighborBo)) {
ringClosures.add(neighborBo);
String ind = ((curIndex > 9) ? "%" : "") + curIndex;
addIndexToAtom(bondToString1(bondOrder[neighborBo]) + ind, atom);
addIndexToAtom(ind, neighborAt);
curIndex++;
}
}
}

// Add atom from the current node
sb.append(getAtomSmarts(curFPMolecule, atom));

// Add indexes
//TODO
if (atomIndexes.containsKey(atom))
sb.append(atomIndexes.get(atom));

// Add branches
if (branches.size() == 0)
Expand All @@ -643,6 +637,17 @@ String nodeToString(int atom)
return sb.toString();
}

void addIndexToAtom(String ind, int atom)
{
if (atomIndexes.containsKey(atom)) {
String old_ind = atomIndexes.get(atom);
atomIndexes.remove(atom);
atomIndexes.put(atom, old_ind + ind);
}
else
atomIndexes.put(atom, ind);
}


private String bondToString1(int boOrder)
{
Expand Down

0 comments on commit 080f776

Please sign in to comment.