User d6c1b7eb8c
10-09-2009 12:43:18
Hi, I've been looking hard for documentation on how to handle molecules on an atomic basis, but the best I could find was http://www.chemaxon.com/jchem/doc/guide/utils/index.html#molhand which says its unlikely that devlopers will need to access the molecule directly, so I apologise if the answer is trivial.
I was wondering how to manually add and remove atoms and bonds. I have experimented but not had much success:
mol = MolHandler('NCCCC').getMolecule()
#Creates Oxygen 'MolAtom'
oxygenAtom = MolAtom(8)
#creates bond between the atoms
bond = MolBond(oxygenAtom, mol.getAtom(3))
however when the molecule is printed toFormat smiles, the oxygen is not present (nor is the atom or bond made present on the molecules bond/atom array).
I have also tried the mol.AddNode0(CNode) method, considering CNodes are abstract I tried:
mol.AddNode0(oxygenAtom)
however this returns the error:
"AttributeError: 'chemaxon.struc.Molecule' object has no attribute 'addNode0'"
So all in all I'm quite confused,
Thanks for any help,
-Ben
ChemAxon 42004978e8
10-09-2009 12:48:32
I move this topic to the appropriate forum.
Robert
User d6c1b7eb8c
10-09-2009 12:49:34
ChemAxon 8b644e6bf4
11-09-2009 12:45:41
Dear Ben,
Use Molecule.add() to add new atoms and bonds. Before adding a bond all of its atoms should be added to the molecule.
Example:
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
import chemaxon.struc.Molecule;
public class Example {
public static void main( String [] args ) throws MolFormatException {
Molecule mol = MolImporter.importMol("NCCCC");
System.out.println("Molecule before: "+mol.toFormat("smiles"));
MolAtom newAtom = new MolAtom(8);
// Add new atom first
mol.add( newAtom );
System.out.println("Molecule after1: "+mol.toFormat("smiles"));
MolBond newBond = new MolBond(newAtom, mol.getAtom(3) );
// Add new bond
mol.add( newBond );
System.out.println("Molecule after2: "+mol.toFormat("smiles"));
}
}
Output:
Molecule before: CCCCN
Molecule after1: O.CCCCN
Molecule after2: CC(O)CCN
If you have any further questions, please do not hesitate to ask them
Regards,
Gabor