Skip to content

Commit

Permalink
Merge pull request #87 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Bugfix: error with charge and multiplicity
  • Loading branch information
seamm authored Nov 27, 2024
2 parents e99691c + 3dec7de commit 89a1c8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=======
History
=======
2024.11.27 -- Bugfix: error with charge and multiplicity
* The charge and multiplicity of the system were not correctly set when creating a
system from a SMILES string using RDKit. More generally, the charge and
multiplicity were not correctly set from an RDKit molecule unless explicitly given
in the properties.

2024.11.23 -- Bugfix: error if OpenEye not available
* Fixed an issue with the import of OpenEye that caused an error if OpenEye was not
available.
Expand Down
12 changes: 11 additions & 1 deletion molsystem/rdkit_.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def to_RDKMol(self, properties=None):
indices = []
rdk_mol = Chem.RWMol()
for atno, _id in zip(self.atoms.atomic_numbers, self.atoms.ids):
idx = rdk_mol.AddAtom(Chem.Atom(atno))
atom = Chem.Atom(atno)
idx = rdk_mol.AddAtom(atom)
index[_id] = idx
indices.append(idx)

Expand Down Expand Up @@ -198,6 +199,15 @@ def from_RDKMol(

data = rdk_mol.GetPropsAsDict()
if self.__class__.__name__ == "_Configuration":
# Charge
self.charge = int(Chem.GetFormalCharge(rdk_mol))

# Calculate spin multiplicity assuming maximal spin
n_electrons = 0
for rdk_atom in rdk_mol.GetAtoms():
n_electrons += rdk_atom.GetNumRadicalElectrons()
self.spin_multiplicity = n_electrons + 1

# Check for property items for charge and multiplicity
if "net charge" in data:
self.charge = int(data["net charge"])
Expand Down

0 comments on commit 89a1c8b

Please sign in to comment.