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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Releases follow the `major.minor.micro` scheme recommended by [PEP440](https://w

### Bugfixes
- [PR #2052](https://github.com/openforcefield/openff-toolkit/pull/2052): Fixes bug where `Topology.from_pdb` couldn't load NH4+ ([Issue #2051](https://github.com/openforcefield/openff-toolkit/issues/2051))
- [PR #2000](https://github.com/openforcefield/openff-toolkit/pull/2000): Assorted type annotation fixes
- [PR #2000](https://github.com/openforcefield/openff-toolkit/pull/2000): `Molecule.to_rdkit()` no longer raises an exception when converting a molecule with non-decimal residue numbers to RDKit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a line here about what happens in this case since the behavior is new and not obviously well-defined


### Miscellaneous

Expand Down
20 changes: 20 additions & 0 deletions openff/toolkit/_tests/test_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,26 @@ def test_to_rdkit_losing_aromaticity_(self):
for offatom, rdatom in zip(mol.atoms, rdmol.GetAtoms()):
assert offatom.is_aromatic is rdatom.GetIsAromatic()

def test_to_rdkit_str_resnum(self):
smiles = ("O")

mol = Molecule.from_smiles(smiles)

# Test an int, a string that can convert to an int, and a non-intable str
atom_resnums = [9998, "9999", "A000"]
# RDKit's default residue number is 0
expected_atom_resnums = [9998, 9999, 0]

for atom, resnum in zip(mol.atoms, atom_resnums):
atom.metadata["residue_number"] = resnum
atom.metadata["residue_name"] = "HOH"

rdmol = mol.to_rdkit()

# now make sure the residue number matches for each atom
for resnum, rdatom in zip(expected_atom_resnums, rdmol.GetAtoms()):
assert rdatom.GetPDBResidueInfo().GetResidueNumber() == resnum

@pytest.mark.slow
def test_max_substructure_matches_can_handle_large_molecule(self):
"""Test RDKitToolkitWrapper substructure search handles more than the default of maxMatches = 1000
Expand Down
7 changes: 4 additions & 3 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 @@ -369,7 +369,8 @@ def from_dict(cls, molecule_dict):
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)
atom1=molecule.atom(atom1_index),
atom2=molecule.atom(atom2_index)
)

conformers = molecule_dict.pop("conformers")
Expand Down
Loading