Page tree

Molecule objects can contain general properties (property value - property key pairs). The formats mrv, sdf, rdf are able to store the molecule properties.

Reading properties after import

In case we know the name of the properties we can use the following code to get the values in text format:

String value = molecule.getProperty(LOGP_FIELD); //LOGP_FIELD is the name of the property

 

Otherwise we need to go through the property names. An example is below:

for (int i=0; i<molecule.getPropertyCount(); i++) {
    String key = molecule.getPropertyKey(i); // name of the property
    String value = molecule.getProperty(key); // the property value
}
 

For a complete source code, please see ImportProperties.java.

Collecting property keys

MolFileHandler.collectFileInfo() enlists the existing property keys:

MolFileHandler.collectFileInfo(inputStream, 0, collectedFields);
java.util.Iterator iterator = collectedFields.iterator();
while (iterator.hasNext()) {
    System.out.println(iterator.next());
}
	

For a complete source code, please see CollectProperties.java.

Adding and exporting properties

The following example shows how to add properties via API:

Molecule mol = MolImporter.importMol("ccccc");
MHashProp hashProp = new MHashProp();
mol.setPropertyObject("ROOT", hashProp);
hashProp.put("CdId", new MStringProp("1"));
hashProp.put("Formula", new MStringProp("C5H10"));
MMoleculeProp secondaryStruc = new MMoleculeProp(MolImporter.importMol("cc"));
hashProp.put("secondStruct", secondaryStruc);
mol.setProperty("$REGNO", "MI24");
System.out.println(MolExporter.exportToFormat(mol, "rdf"));

 

For a complete source code, please see ExportProperties.java.

External or internal registry number of a molecule can be added to the molecule or reaction via API. The mrv, mol (sdf, rdf) format exports and imports these registry numbers after specifying them:

int regno = 218;
while ((mol=imp.read())!=null){
    //add the internal registry number (sequence number in the database) of the reaction
    mol.setProperty("$REGNO", "RI" + regno);
    regno++;
    exp.write(mol);  
}

 

For a complete source code, please see ExportingReactions.java.