Get substructure from molecule

User da00f5c453

20-11-2007 23:55:35

Hi everyone,





I am trying to build a custom query application, I am starting with a query molecule determine it SSSR and I want to use the determined SSSR to query a list of structures. What is the best way to extract a molcular fragment from a Molecule object if I have the atom ids from getSSSR() function.





my code to get the SSSR is:





Molecule mol = MolImporter.importMol("CC(C)N1C=CC2=CC=CC=C12");


mol.aromatize();


int[][] rings = mol.getSSSR();





now I want to use the ring system as molecular query. I looked in the API and couldn't find the best way to do it.





Oleg.

ChemAxon 9c0afc9aaf

21-11-2007 10:37:36

Hi,





You may remove all nodes (and bonds) not listed amongst the ring atoms:





Code:
Molecule.removeNode(int)






This also removes bonds connected to this node.


Indexing starts from 0.


Remove the nodes in decreasing order so the indexes of the remaining nodes to be removed do not change.





Please see:





http://www.chemaxon.com/jchem/doc/api/chemaxon/struc/CGraph.html#removeNode(int)


and


http://www.chemaxon.com/jchem/doc/api/chemaxon/struc/MoleculeGraph.html#getAtomCount()





Best regards,





Szilard

User da00f5c453

21-11-2007 17:03:28

thanks Szilard it works fine now.





Code:



Molecule mol = MolImporter.importMol("CC(C)N1C=CC2=CC=CC=C12");


mol.aromatize();


int[][] rings = mol.getSSSR();


HashSet<Integer> keepNodes = new HashSet<Integer>();


for(int[] r : rings) {


  for(int n : r) {


   keepNodes.add(n);


  }


}


Molecule query = mol.cloneMolecule();


for(int i = query.getAtomCount() - 1; i >= 0; i--) {


   if(!keepNodes.contains(i)) {


      query.removeNode(i);


   }


}








Oleg.