Skip to content

Commit

Permalink
Check value of bond_order and throw error if invalid, fix typos and s…
Browse files Browse the repository at this point in the history
…tring formatting
  • Loading branch information
chrisjonesBSU committed Oct 18, 2023
1 parent 0e8cbe7 commit 3adb518
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,29 @@ def add_bond(self, particle_pair, bond_order=None):
The pair of Particles to add a bond between
bond_order : float, optional, default=None
Bond order of the bond.
Available options include "default", "single", "double",
"triple", "aromatic" or "unspecified"
"""
if self.root.bond_graph is None:
self.root.bond_graph = BondGraph()
if bond_order is None:
bond_order = "default"
else:
if bond_order.lower() not in [
"single",
"double",
"triple",
"aromatic",
"unspecified",
]:
raise ValueError(
"Invalid bond_order given. Available bond orders are: "
"single",
"double",
"triple",
"aromatic",
"unspecified",
)
self.root.bond_graph.add_edge(
particle_pair[0], particle_pair[1], bo=bond_order
)
Expand Down Expand Up @@ -3245,6 +3263,7 @@ def from_parmed(self, structure, coords_only=False, infer_hierarchy=True):
)

def to_rdkit(self):
"""Create an RDKit RWMol from an mBuild Compound."""
rdkit = import_("rdkit")
from rdkit import Chem
from rdkit.Chem import AllChem
Expand All @@ -3258,11 +3277,10 @@ def to_rdkit(self):
particle._element = element_from_name(particle.name)
except ElementError:
raise MBuildError(
"No element assigned to {}; element could not be"
"inferred from particle name {}. Cannot perform"
"an energy minimization.".format(
particle, particle.name
)
f"No element assigned to {particle};"
"element could not be"
f"inferred from particle name {particle.name}."
" Cannot perform an energy minimization."
)

temp_mol = Chem.RWMol()
Expand All @@ -3281,7 +3299,7 @@ def to_rdkit(self):
temp_atom = Chem.Atom(particle.element.atomic_number)

# this next line is necessary to prevent rdkit from adding hydrogens
# this will also set the label to be the lement with particle index
# this will also set the label to be the element with particle index
temp_atom.SetProp(
"atomLabel", f"{temp_atom.GetSymbol()}:{p_dict[particle]}"
)
Expand Down

0 comments on commit 3adb518

Please sign in to comment.