File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -3508,6 +3508,26 @@ def test_to_rdkit_losing_aromaticity_(self):
3508
3508
for offatom , rdatom in zip (mol .atoms , rdmol .GetAtoms ()):
3509
3509
assert offatom .is_aromatic is rdatom .GetIsAromatic ()
3510
3510
3511
+ def test_to_rdkit_str_resnum (self ):
3512
+ smiles = ("O" )
3513
+
3514
+ mol = Molecule .from_smiles (smiles )
3515
+
3516
+ # Test an int, a string that can convert to an int, and a non-intable str
3517
+ atom_resnums = [9998 , "9999" , "A000" ]
3518
+ # RDKit's default residue number is 0
3519
+ expected_atom_resnums = [9998 , 9999 , 0 ]
3520
+
3521
+ for atom , resnum in zip (mol .atoms , atom_resnums ):
3522
+ atom .metadata ["residue_number" ] = resnum
3523
+ atom .metadata ["residue_name" ] = "HOH"
3524
+
3525
+ rdmol = mol .to_rdkit ()
3526
+
3527
+ # now make sure the residue number matches for each atom
3528
+ for resnum , rdatom in zip (expected_atom_resnums , rdmol .GetAtoms ()):
3529
+ assert rdatom .GetPDBResidueInfo ().GetResidueNumber () == resnum
3530
+
3511
3531
@pytest .mark .slow
3512
3532
def test_max_substructure_matches_can_handle_large_molecule (self ):
3513
3533
"""Test RDKitToolkitWrapper substructure search handles more than the default of maxMatches = 1000
Original file line number Diff line number Diff line change @@ -2716,8 +2716,14 @@ def to_rdkit(
2716
2716
res .SetResidueName (atom .metadata ["residue_name" ])
2717
2717
2718
2718
if "residue_number" in atom .metadata :
2719
- atom_has_any_metadata = True
2720
- res .SetResidueNumber (int (atom .metadata ["residue_number" ]))
2719
+ try :
2720
+ residue_number_int = int (atom .metadata ["residue_number" ])
2721
+ except ValueError :
2722
+ # Residue number is a string that could not be converted to int
2723
+ pass
2724
+ else :
2725
+ atom_has_any_metadata = True
2726
+ res .SetResidueNumber (residue_number_int )
2721
2727
2722
2728
if "insertion_code" in atom .metadata :
2723
2729
atom_has_any_metadata = True
You can’t perform that action at this time.
0 commit comments