21import java.lang.reflect.Type;
22import java.util.ArrayList;
25import org.openscience.cdk.interfaces.IAtom;
26import org.openscience.cdk.interfaces.IAtomContainer;
27import org.openscience.cdk.interfaces.IBond;
29import com.google.gson.JsonElement;
30import com.google.gson.JsonObject;
31import com.google.gson.JsonSerializationContext;
32import com.google.gson.JsonSerializer;
34import denoptim.utils.MoleculeUtils;
52 protected static final String
ATOMSKEY =
"atoms";
57 protected static final String
BONDSKEY =
"bonds";
60 public JsonElement
serialize(IAtomContainer iac, Type typeOfSrc,
61 JsonSerializationContext context)
63 JsonObject jsonObject =
new JsonObject();
64 List<LWAtom> atoms =
new ArrayList<LWAtom>();
65 for (IAtom atm : iac.atoms())
70 List<LWBond> bonds =
new ArrayList<LWBond>();
71 for (IBond bnd : iac.bonds())
73 bonds.add(
new LWBond(iac.indexOf(bnd.getAtom(0)),
74 iac.indexOf(bnd.getAtom(1)), bnd.getOrder()));
77 jsonObject.add(
ATOMSKEY, context.serialize(atoms));
78 jsonObject.add(
BONDSKEY, context.serialize(bonds));
Class to serialise CDK's IAtomContainer in a simplified manner.
JsonElement serialize(IAtomContainer iac, Type typeOfSrc, JsonSerializationContext context)
static final String ATOMSKEY
String used to identify the list of atoms in json map.
static final String BONDSKEY
String used to identify the list of bonds in json map.
A light-weight atom representation to facilitate json serialization of IAtom.
A light-weight bond representation to facilitate json serialization of IBond.
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
static Point3d getPoint3d(IAtom atm)
Return the 3D coordinates, if present.