MolAtom

The chemaxon.struc.MolAtom class is used to represent chemical atoms. To create a MolAtom object, one of these constructor methods can be used:

  • MolAtom(int Z, double x, double y, double z);

  • MolAtom(int Z, double x, double y);

  • MolAtom(int Z);

Here int Z is the atomic number; double x, double y, double z, are the coordinates of the atom. If the coordinates are not given, they are automatically set to zero. The atomic number can be specified using the constants in the static class, chemaxon.struc.PeriodicSystem.

Code examples

Creating an Oxygen MolAtom object
MolAtom o = new MolAtom(PeriodicSystem.O);

If the constructed MolAtom object is supposed to be a part of MoleculeGraph (or its subclasses), then it should be added to it using the add(MolAtom) method:

Adding an atom to a molecule
molecule.add(o);

Complete working code examples

Building simple CO molecule using MolAtom objects
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
 
import chemaxon.formats.MolExporter;
import chemaxon.struc.*;
/**
* Example class for structure manipulation. Creates CO
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class BuildMoleculeCO {
public static void main(String[] args) throws IOException{
 
// create an empty Molecule
Molecule m = new Molecule();
 
// create the Carbon atom
MolAtom a1 = new MolAtom(6);
// and add it to the molecule
m.add(a1);
 
// create the Oxygen atom
MolAtom a2 = new MolAtom(8);
// and add it to the molecule
m.add(a2);
 
System.out.println(MolExporter.exportToFormat(m,"smiles"));
// this prints C.O as no bond has been defined yet
 
// create a bond between atoms, bond order
MolBond b = new MolBond(a1, a2, 2);
m.add(b);
System.out.println(MolExporter.exportToFormat(m,"smiles"));
// this prints C=O
}
}
Accessing atoms and bonds of the molecule
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
/**
* Example class to demonstrate how to access atoms and bonds
* of the molecule.
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class MoleculeAtoms {
public static void main(String[] args) {
String filename = args[0];
try {
// create a molecule importer for the given file
MolImporter mi = new MolImporter(filename);
 
// read the first molecule from the file
Molecule m = mi.read();
 
while (m != null) {
printAtoms(m);
printBonds(m);
// read the next molecule from the input file
m = mi.read();
}
mi.close();
}
catch (MolFormatException e) {
System.err.println("Molecule format not recognised.");
}
catch (IOException e) {
System.err.println("I/O error:" + e);
}
}
private static void printAtoms( Molecule m ) {
m.calcHybridization();
System.out.println("Atoms in the molecule\natomic number\tcharge\thybridisation");
for (int i = 0; i < m.getAtomCount(); i++) {
MolAtom a = m.getAtom(i);
System.out.println( i + "th atom: " + a.getAtno() + "\t\t"
+ a.getCharge() + "\t"
+ a.getHybridizationState());
}
}
private static void printBonds( Molecule m ) {
System.out.println("Bonds in the molecule\nbond order\tcoodinate");
for (int i = 0; i < m.getBondCount(); i++) {
MolBond b = m.getBond(i);
System.out.println( b.getType() + "\t\t" + b.isCoordinate() + " "
+ m.indexOf( b.getAtom1()) + "-" + m.indexOf( b.getAtom2()));
}
}
}

The following table summarizes which properties of the MolAtom object have set or get methods.

property

set

get

note

Index

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/error0.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

assigned automatically

Bonds

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

Atomic number, type

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

Atomic mass

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Radical

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Charge

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Coordinates

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Atomic map

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Alias string

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

 

Valence

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

calculated

Implicit hydrogen count

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

calculated

Hybridization

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

images/s/en_GB/6219/97b73ca06fd2a90682d80f34d4c4c163eebdd511.89/_/images/icons/emoticons/check.png

calculated separately

General atomic properties of atoms that are not related to the molecular context (e.g. mass, isotope count etc.) are available in the class PeriodicSystem.

Working example of retaining atomic properties of C using class PeriodicSystem
/*
* Copyright (c) 1998-2014 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 chemaxon.examples.strucrep;
 
import chemaxon.struc.PeriodicSystem;
import static chemaxon.struc.PeriodicSystem.*;
 
/**
* Example methods of the PeriodicSystem class.
*
* @author Janos Kendi
*
*/
public class PeriodicSystemExample {
 
public static void main(String[] args) {
 
System.out.println("Atomic number of C: "
+ PeriodicSystem.findAtomicNumber("C"));
 
System.out.println("Mass of C: " + PeriodicSystem.getMass(C));
 
System.out.println("Column of C: " + PeriodicSystem.getColumn(C));
 
System.out.println("Number of C isotopes: "
+ PeriodicSystem.getIsotopeCount(C));
}
}