Skip to content

Improve some typing #2000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions openff/toolkit/topology/_mm_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def n_bonds(self) -> int:
def n_conformers(self) -> int:
return 0 if self._conformers is None else len(self._conformers)

def atom(self, index):
def atom(self, index: int) -> "_SimpleAtom":
return self.atoms[index]

def atom_index(self, atom) -> int:
return self.atoms.index(atom)

def bond(self, index):
def bond(self, index: int) -> "_SimpleBond":
return self.bonds[index]

def get_bond_between(self, atom1_index, atom2_index):
Expand Down Expand Up @@ -340,9 +340,7 @@ def to_dict(self) -> dict:
molecule_dict["conformers"] = None
else:
molecule_dict["conformers"] = []
molecule_dict["conformers_unit"] = (
"angstrom" # Have this defined as a class variable?
)
molecule_dict["conformers_unit"] = "angstrom" # Have this defined as a class variable?
for conf in self._conformers:
conf_unitless = conf.m_as(unit.angstrom)
conf_serialized, conf_shape = serialize_numpy(conf_unitless)
Expand All @@ -368,9 +366,7 @@ def from_dict(cls, molecule_dict):
for bond_dict in bond_dicts:
atom1_index = bond_dict["atom1_index"]
atom2_index = bond_dict["atom2_index"]
molecule.add_bond(
atom1=molecule.atom(atom1_index), atom2=molecule.atom(atom2_index)
)
molecule.add_bond(atom1=molecule.atom(atom1_index), atom2=molecule.atom(atom2_index))

conformers = molecule_dict.pop("conformers")
if conformers is None:
Expand Down Expand Up @@ -438,9 +434,7 @@ def to_molecule(self) -> NoReturn:
"an OpenFF Molecule with sufficiently specified chemistry."
)

def is_isomorphic_with(
self, other: Union["FrozenMolecule", "_SimpleMolecule", "nx.Graph"], **kwargs
) -> bool:
def is_isomorphic_with(self, other: Union["FrozenMolecule", "_SimpleMolecule", "nx.Graph"], **kwargs) -> bool:
"""
Check for pseudo-isomorphism.

Expand Down Expand Up @@ -504,9 +498,7 @@ def node_match_func(node1, node2):
if return_atom_map:
topology_atom_map = matcher.mapping

return True, {
key: topology_atom_map[key] for key in sorted(topology_atom_map)
}
return True, {key: topology_atom_map[key] for key in sorted(topology_atom_map)}

else:
return True, None
Expand Down Expand Up @@ -534,9 +526,7 @@ def __getattr__(self, name: str) -> list["HierarchyElement"]:
try:
return self.__dict__["_hierarchy_schemes"][name].hierarchy_elements
except KeyError:
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute {name!r}"
)
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute {name!r}")

def __deepcopy__(self, memo):
return self.__class__.from_dict(self.to_dict())
Expand Down Expand Up @@ -585,10 +575,7 @@ def atomic_number(self, value):
if not isinstance(value, int):
raise ValueError("atomic_number must be an integer")
if value < 0:
raise ValueError(
"atomic_number must be non-negative. An atomic number "
"of 0 is acceptable."
)
raise ValueError("atomic_number must be non-negative. An atomic number of 0 is acceptable.")
self._atomic_number = value

@property
Expand Down
Loading