User 568550d85a
16-09-2008 16:12:46
It would be nice to be able to get an int[][] containing the smallest set of smallest ring bond indices (not the atom indices). I don't know if it already exsits, please tell me if so. If not here is a proposal:
lorenz
lorenz
Code: |
import chemaxon.struc.Molecule; import chemaxon.util.MolHandler; public class SSSRB { public static void main(String[] args) throws Exception { int[][] sssrb = new SSSRB().getSSSRBonds(new MolHandler("C12CC=C1CCOC2CCC").getMolecule()); for (int i = 0; i < sssrb.length; i++) { for (int j = 0; j < sssrb[i].length; j++) { System.out.println("Ring "+i+" Bond "+sssrb[i][j]); } } } public int[][] getSSSRBonds(Molecule m) { int[][] sssr = m.getSSSR(); int[][] btab = m.getBtab(); int[][] sssrb = new int[sssr.length][0]; //Loop through rings for (int i = 0; i < sssr.length; i++) { //bonds will contain bonds of ring i int[] bonds = new int[0]; for (int j = 0; j < sssr[i].length; j++) { for (int k = j+1; k < sssr[i].length; k++) { //if atom j and k (of ring i) are connected then add bond to bonds int bond = btab[sssr[i][j]][sssr[i][k]]; if(bond!=-1) { bonds = addInt(bonds, bond); } } } sssrb[i] = bonds; } return sssrb; } private int[] addInt(int[] arr, int i) { int[] temp = arr; int size = temp.length; arr = new int[size+1]; System.arraycopy(temp, 0, arr, 0, size); arr[size] = i; return arr; } } |