How to get the formula of the constant part of a polymer?

User e6dac1475d

10-01-2014 15:37:00

Dear ChemAxon team,


I am using the Java API v6.1.3 and I would like to get the formula for a constant part of a polymer, starting from a molfile. How can I do it?


Example:


Given the following compound (see attached molfile ChEBI_15693.mol), which is an aldose, with a RepeatingUnitSgroup (SRU):


If I do:


import chemaxon.struc.Molecule;


[...]


MolImporter importer = new MolImporter(new ByteArrayInputStream(structure.getBytes()));
Molecule mol = importer.read();
[...] mol.getFormula()


I get:


(CH2O)nC2H4O2

How do I get  C2H4O2 only?


I tried the two following possibilities:


1. I can't perform mol.removeAllSGroups() before calling getFormula() (Molecule.removeAllSGroups() is protected)


2, I tried the ElementalAnalyserPlugin, getFormula(), but I get:


java.lang.NullPointerException
    at chemaxon.struc.Molecule.addSgroupClone(Molecule.java:1046)

[...]


 


Do you have a suggestion to get C2H4O2 out of this molfile in a clean way?


Thanks for you support,


Thierry

ChemAxon d26931946c

14-01-2014 14:22:45

Hi Thierry,


Unfortunately there is no convenient way of doing such thing. I can suggest you to use the functionality of the SelectionMolecule for this. Here is a simple code that calculates the formula for the parts that are not in any Sgroup:


SelectionMolecule sm = new SelectionMolecule();
for (MolAtom ma : m.getAtomArray()) {
   if (m.findSgroupOf(ma) == null) {
       sm.add(ma);
    }
}
System.out.println("Formula for selection: " + sm.getFormula());



 


Please let us know if this solution is suitable for you.


Regards,


Peter

User e6dac1475d

15-01-2014 14:08:31

Dear Peter,


The solution that you propose is working fine in my context.


Thanks for your help indeed!


Best regards,


 


Thierry