Molecule mol; Atom a1, a2; a1.setAtomicNumber(6); // carbon a2.setAtomicNumber(1); // hydrogen mol.addAtom(a1); mol.addAtom(a2); mol.addBond(0, 1); // add bond between atoms at index 0 and index 1
Molecule mol; Atom a1, a2, a3; a1.setAtomicNumber(8); // oxygen a2.setAtomicNumber(1); // hydrogen a3.setAtomicNumber(1); // hydrogen mol.addAtom(a1); mol.addAtom(a2); mol.addAtom(a3); mol.addBond(0, 1); // add bond between oxygen and first hydrogen mol.addBond(0, 2); // add bond between oxygen and second hydrogenIn this example, an oxygen atom and two hydrogen atoms are added to the molecule. Two covalent bonds are formed between the oxygen atom and each of the hydrogen atoms, creating a water molecule. The package library that contains the Molecule and Atom classes and the addBond function is likely a molecular modeling software library or toolkit, such as Open Babel or RDKit.