I’ve thought about this a bit, not surprisingly.
There’s definitely a need for scripts to indicate “I have some new properties, just add them to the current molecule.” For example, it’s easy to get xtb
to punch a Molden file, and then ask Avogadro to read that. But you don’t really want to replace the current molecule … maybe you’ve carefully set up bond orders, put some atoms in different layers … whatever.
In the meantime, I think you want to request cjson
from Avogadro.
- The
cjson
will track total charge and spin multiplicity
- The
cjson
will include lattice vectors if you have a periodic system.
- It’s easy enough to just update the coordinates when you pass back the
cjson
to Avogadro.
- You can add properties to the
cjson
before you pass it back.
atoms = np.array(mol_cjson["atoms"]["elements"]["number"])
coord_list = mol_cjson["atoms"]["coords"]["3d"]
coordinates = np.array(coord_list, dtype=float).reshape(-1, 3)
charge = None # neutral
spin = None # singlet
if "properties" in mol_cjson:
if "totalCharge" in mol_cjson["properties"]:
charge = mol_cjson["properties"]["totalCharge"]
if "totalSpinMultiplicity" in mol_cjson["properties"]:
spin = mol_cjson["properties"]["totalSpinMultiplicity"]
Then let’s say you get new coordinates from the XYZ output from xtb
:
mol_cjson["atoms"]["coords"]["3d"] = new_coords.reshape(-1)
For cases where you want to return multiple conformers or a trajectory:
mol_cjson["atoms"]["coords"]["3dsets"] = [ [ … ], [ …] ]
I think there are probably other use cases (e.g., orbitals, vibrations) in which it’s probably easier to say “I want add properties from this file, but not change atoms / bonds.”
I’m leaning towards this syntax:
{
"moleculeFormat": "molden",
"ignoreAtoms": true
}
I’m not sure the best name for the key… “ignoreAtoms” or “readProperties”.
I think there’s probably also merit to just returning properties (e.g., some script that calculates pKa or whatever):
{
properties: { "pkA": 6.74 }
}
The CJSON specification is on GitHub - I’m happy to consider improvements: https://github.com/OpenChemistry/chemicaljson/master/chemicaljson.py