# OEMolRecord¶

OEMolRecord is a specialized OERecord with some extra methods for handling molecules. The presence of convenience methods for handling molecules is the only difference between an OEMolRecord and an OERecord. The underlying representation is identical, and either class can be copy-constructed from the other with no loss of information.

The following example shows how an OEMolRecord can be used, and illustrates that OEMolRecords are just OERecords with some additional methods.

toluene = OEMol()
OESmilesToMol(toluene, "c1ccccc1C")
mol_record = OEMolRecord()
mol_record.set_mol(toluene)  # Sets the molecule on a field named "Molecule"
print(mol_record.has_mol())  # True
better_be_toluene = mol_record.get_mol()

# Show that an OEMolRecord is just an OERecord underneath
molecule_field = mol_record.get_primary_mol_field()
normal_record = OERecord(mol_record)
print(normal_record.has_field(molecule_field))  # True
other_mol_record = OEMolRecord(normal_record)
print(other_mol_record.has_mol())  # True


## Conformer data on records¶

OEMolRecord also has methods for managing data for conformers. Each conformer of a molecule can get its own record to store conformer-specific data onto.

# Create some empty conformers
conf1 = toluene.NewConf()
conf2 = toluene.NewConf()

# We'll attach a record to each conformer
score_field = OEField("score", Types.Float)
conf1_record = mol_record.get_conf_record(conf1)
conf2_record = mol_record.get_conf_record(conf1)

# Now we put a score onto each conformer's record
conf1_record.set_value(score_field, 10.0)
mol_record.set_conf_record(conf1, conf1_record)

conf2_record.set_value(score_field, 20.0)
mol_record.set_conf_record(conf2, conf2_record)

# IMPORTANT: You must set the conformers' parent molecule on the record
# at some point after setting conformer records and before the record is
# saved. Otherwise the conformer data will be lost.
mol_record.set_mol(toluene)

# We only set a single value for each conformer, but we could have
# put any number of fields and values on each conformer's record.
print(mol_record.get_conf_record(conf2).get_value(score_field))  # 20.0