michellab / BioSimSpace

Code and resources for the EPSRC BioSimSpace project.
https://biosimspace.org
GNU General Public License v3.0
77 stars 19 forks source link

Pickling a parametrised molecule from an SDF file with GAFF2 #415

Closed msuruzhon closed 1 year ago

msuruzhon commented 1 year ago

Hi,

This might be one for sire, but I am observing a strange bug when loading a molecule from an SDF file, parametrising it with GAFF2, and then trying to pickle it. Consider this script using a simple benzene SDF:

import pickle

import BioSimSpace.Sandpit.Exscientia as BSS

mol = BSS.IO.readMolecules(["benzene.sdf"])[0]
param_mol = BSS.Parameters.gaff2(mol).getMolecule()
pickle.dumps(param_mol)

The following error is thrown:

UserWarning: SireError::program_bug: There was an error saving the object of type "SireMol::AtomStringArrayProperty". Has the programmer remembered to add a RegisterMetaType for this class? (call sire.error.get_last_error_details() for more info)

This is fixed if one reloads the generated molecule through a prm7/rst7 file so presumably it is something that is cached in the sire layer that doesn't get properly updated?

Many thanks.

chryswoods commented 1 year ago

Thanks for finding this - it is definitely a sire bug. I've either forgotten to add the registrar for the metatype for the class, or there is some shared library weirdness that is meaning that the metatype is not being found on load. I'll take a look and debug :-)

chryswoods commented 1 year ago

Yes - I'd forgotten to register the meta types for a number of AtomProperty classes that are used to store atom properties loaded from SDF files. Your fix of going to/from a prm7/rst7 file worked because it removed those properties from the molecule.

I have raised this pull request in openbiosim/sire that will fix the issue. It will be in the dev package of openbiosim/sire later today (once the CI has run) and then in the main release once we have enough bugfixes or new features to justify a release.

msuruzhon commented 1 year ago

Great, many thanks @chryswoods. I guess we can close this issue here then?

chryswoods commented 1 year ago

Yes - I'll close it here. The pull request checks have almost finished, and @lohedges has reviewed the change. The CI/CD should finish building an updated dev Conda package by likely 6-7pm.