MolBond

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

  • MolBond(MolAtom a1, MolAtom a2, int f)

  • MolBond(MolAtom a1, MolAtom a2)

  • MolBond(MolBond b)

The two MolAtom objects in the constructors defines between which atoms is the bond defined. The int f constant defines the type of the bond. The value can be:

  • 1 - single bond

  • 2 - double bond

  • 3 - triple bond

  • MolBond.AROMATIC - aromatic bond

  • MolBond.SINGLE_OR_DOUBLE - bond, that can be both single and double

  • MolBond.SINGLE_OR_AROMATIC - bond, that can be both single and aromatic

  • MolBond.DOUBLE_OR_AROMATIC - bond, that can be both double and aromatic

  • MolBond.CONJUGATED - conjugated bond

  • MolBond.COORDINATE - coordinated bond

  • MolBond.UP - single bond up

  • MolBond.DOWN - single bond down

  • MolBond.WAVY - single bond up or down

  • MolBond.STEREO1_MASK - single bond stereo mask. It is the same as UP | DOWN

  • MolBond.STEREO2_CARE - Cis/trans info of this bond is taken care of during the SSS process, used only for query bonds

  • MolBond.STEREO_MASK - Single and double bond stereo mask. It is the same as STEREO1_MASK | CTUMASK | STEREO2_CARE

  • MolBond.ANY - any bond

If this constant is omitted, single bond object will be created.

Similarly to the MolAtom the constructed MolBond object should be added to the molecule it belongs to.

Code examples

Build water molecule using MolAtom and MolBond objects
package chemaxon.examples.strucrep
 
import chemaxon.struc.*;
 
/**
* Example class for structure manipulation. Creates water.
*
* @author Andras Volford
*
*/
public class BuildMoleculeWater {
 
public static void main(String[] args) {
 
// create an empty Molecule
Molecule m = new Molecule();
 
// create the Carbon atom
MolAtom a1 = new MolAtom(8);
// and add it to the molecule
m.add(a1);
 
// create the Hydrogen atom
MolAtom a2 = new MolAtom(1);
// and add it to the molecule
m.add(a2);
 
// create the Hydrogen atom
MolAtom a3 = new MolAtom(1);
// and add it to the molecule
m.add(a3);
System.out.println(m.toFormat("smiles"));
// this prints [H+].[H+].O as no bond has been defined yet
 
// create a bond between atoms, bond order
MolBond b1 = new MolBond(a1, a2, 1);
m.add(b1);
MolBond b2 = new MolBond(a1, a3, 1);
m.add(b2);
System.out.println(m.toFormat("smiles"));
// this prints water
}
}
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 if the properties of the MolBond 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

2 endpoints – 2 nodes

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

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

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

Stereo information

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

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

wedge / double bond stereo detailed in stereo chemistry