Only allow adding real molcules

User 65339aced8

13-08-2004 19:19:07

Hi Szilard,





How can I prevent adding of smarts to the structures table.


Currently I check whether smiles include '$['. Which is not sufficient.


I guess you know a better way.





Sincerely,





Niels.

ChemAxon 9c0afc9aaf

14-08-2004 17:03:04

Hi Niels,





You should import the structure into a Molecule object.


The you can determine the file format of the structure, but there are file formats which can describe both query and "real" structures.


Therefore I recommend to check for other query features, such as R-groups, atom lists, any atoms and so on.





The following code demonstrates the inspection of some of these properties:


(see the Molecule API for more information)





Code:



        Molecule mol=MolImporter.importMol(molstring);


        if (mol.getInputFormat().equals("smarts")) {


            System.out.println("SMARTS !");


        }


        if (mol instanceof RgMolecule) {


            if (((RgMolecule) mol).getRgroupCount()>0) {


                System.out.println("R-group query !");


            }


        }


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


            MolAtom atom=mol.getAtom(x);


            if (atom.getAtno()>MolAtom.ELEMENT_COUNT) {


                System.out.println("Special atom type !");


            }


            if (atom.getQuerystr()!=null) {


                System.out.println("Query properties on atom !");


            }





            if (atom.isQuery()) {


                System.out.println("Query !");


            }


            if (atom.isQProp()) {


                System.out.println("Query property !");


            }





            if (atom.getList()!=null) {


                System.out.println("Atom list !");


            }


        }


User 65339aced8

14-08-2004 17:11:10

Thanks. That is what I need. Sincerely, Niels.

ChemAxon a3d59b832c

17-08-2004 14:33:05

Hi!





Don't forget the query bonds:





Code:



    for (int x = 0; x < mol.getBondCount(); x++) {


        MolBond bond = mol.getBond(x);


        if (bond.isQuery() || // Query bond type


            ((bond.getFlags() & MolBond.TOPOLOGY_MASK)!=0) || // chain/ring bond


            (bond.getQuerystr() != null ) // (smarts bond)


        ) {


            System.out.println("   QUERY BOND!");


        }


    }//end for(x)








Additionally, from the next release (Marvin 3.5?) toFormat("smiles") will throw an exception if there is a feature in the molecule which cannot be represented as smiles, i.e. in all the above cases, except ANY atom.





Szabolcs