Deleting Single Bonded Atoms

User 9fa69eb201

27-10-2006 05:21:27

Dear All,





I just want to know if anybody can help me in a program which deletes all the atoms bonded to a single atom. I have attached here a sample mole file which contains the original structure and the structure(output) i wanted.





Thanks in advance





Aniraj

ChemAxon a3d59b832c

27-10-2006 11:29:28

The easiest to achieve this with Standardizer.





See the second example on page 2 of the Standardizer poster.





Let me know if you prefer Java code.

User 9fa69eb201

27-10-2006 11:59:50

Dear Sir,





I am presently going through the File you have mentioned but i think the java code for the same would be a great help in quick understanding. I woul like to have the java code Sir.





Thanks in Advance





Aniraj

ChemAxon a3d59b832c

27-10-2006 12:45:45

See the code below. I modified the code for SimpleConverter from the Marvin Beans examples: http://www.chemaxon.com/marvin/examples/index.html





This page contains the API documentation of the used classes and methods: http://www.chemaxon.com/marvin/doc/api/





Code:
/*


 * Copyright (c) 1998-2005 ChemAxon Ltd. All Rights Reserved.


 *


 * This software is the confidential and proprietary information of


 * ChemAxon. You shall not disclose such Confidential Information


 * and shall use it only in accordance with the terms of the agreements


 * you entered into with ChemAxon.


 *


 */


package test;





import chemaxon.formats.MolImporter;


import chemaxon.struc.Molecule;


import chemaxon.struc.MolAtom;





import java.io.OutputStream;


import java.io.FileOutputStream;





/**


 * Simple molecule file converter.


 */


public class OneBondAtomRemover {


    public static void main(String[] args) throws Exception {


        if(args.length < 1) {


            System.out.println(


                "Usage: OneBondAtomRemover input_file format\n"+


                "Example: OneBondAtomRemover caffeine.mol");


            System.exit(0);


        }


        MolImporter importer = new MolImporter(args[0]);


        Molecule mol = importer.read();





        removeOneBondAtoms(mol);





        String format = "mol";


        byte[] data = mol.toBinFormat(format);


        if(data == null) {


            System.err.println("Cannot export molecule in \""


                                + format + "\" format.");


            System.exit(1);


        }


        String outfile = "output."+format;


        OutputStream out = new FileOutputStream(outfile);


        out.write(data);


        out.close();


        System.out.println("Output written to file " + outfile);


        System.exit(0);


    }





    private static void removeOneBondAtoms(Molecule mol) {


        int i = findOneBondAtom(mol);


        while(i != -1) {


            mol.removeNode(i);


            i = findOneBondAtom(mol);


        }


    }





    private static int findOneBondAtom(Molecule mol) {


        for (int i = 0; i < mol.getAtomCount(); i++) {


            MolAtom ma = mol.getAtom(i);


            if (ma.getBondCount() == 1) {


                return i;


            }


        }//end for(i)





        return -1;


    }


}


User 9fa69eb201

29-10-2006 02:58:25

Thanks for the same and it really works so good, i have the small idea of removing the single boded atoms but i am not able to put the code properly. I can use this for writing a big program which is very useful for me.





Thanks once again for the quick response.





Thanks and regards





Aniraj