Recipe 2.1.1. Building molecule expression
Problem
You want to create new molecules from expression.
Solution
ChemicalFacade provide a way to create a molecule from expression of others molecule or formulae:
import org.expasy.jpl.core.mol.chem.ChemicalFacade; Molecule molecule = ChemicalFacade.newMolecularExpressionBuilder() .plus("CH3").plus("NH4").build(); // CH7N System.out.println(molecule); Molecule otherMolecule = ChemicalFacade.newMolecularExpressionBuilder() .plus(molecule).plus("NH4").build(); // CH11N2 System.out.println(otherMolecule); Molecule sameFirstMolecule = ChemicalFacade.newMolecularExpressionBuilder() .plus(otherMolecule).minus("NH4").build(); // CH7N System.out.println(sameFirstMolecule); Assert.assertTrue(molecule.equals(sameFirstMolecule));
Discussion
See Also