@@ -26,3 +26,68 @@ def test_read_pdb_components_file_parses_all_for_empty_include(tmp_path):
2626 assert list (result ) == ["00O" , "007" ]
2727
2828
29+ def test_read_pdb_components_file_uses_include_order_and_skips_missing (
30+ tmp_path , caplog
31+ ):
32+ path = _components_cif (tmp_path )
33+
34+ with caplog .at_level (logging .WARNING ):
35+ result = ccd_reader .read_pdb_components_file (
36+ str (path ), sanitize = False , include = ["007" , "MISSING" , "00O" , "007" ]
37+ )
38+
39+ assert list (result ) == ["007" , "00O" ]
40+ assert "Data block MISSING not found" in caplog .text
41+
42+
43+ def test_parse_pdb_bonds_uses_atom_id_lookup ():
44+ block = cif .read_string (
45+ """
46+ data_TST
47+ loop_
48+ _chem_comp_atom.atom_id
49+ A
50+ B
51+ loop_
52+ _chem_comp_bond.atom_id_1
53+ _chem_comp_bond.atom_id_2
54+ _chem_comp_bond.value_order
55+ A B SING
56+ """
57+ ).sole_block ()
58+ mol = Chem .RWMol ()
59+ mol .AddAtom (Chem .Atom ("C" ))
60+ mol .AddAtom (Chem .Atom ("O" ))
61+ errors = []
62+
63+ ccd_reader ._parse_pdb_bonds (mol , block , errors )
64+
65+ assert errors == []
66+ assert mol .GetNumBonds () == 1
67+ assert mol .GetBondBetweenAtoms (0 , 1 ) is not None
68+
69+
70+ def test_parse_pdb_bonds_missing_atom_1_does_not_mask_error ():
71+ block = cif .read_string (
72+ """
73+ data_TST
74+ loop_
75+ _chem_comp_atom.atom_id
76+ A
77+ loop_
78+ _chem_comp_bond.atom_id_1
79+ _chem_comp_bond.atom_id_2
80+ _chem_comp_bond.value_order
81+ ? A SING
82+ """
83+ ).sole_block ()
84+ mol = Chem .RWMol ()
85+ mol .AddAtom (Chem .Atom ("C" ))
86+ errors = []
87+
88+ ccd_reader ._parse_pdb_bonds (mol , block , errors )
89+
90+ assert errors == [
91+ f"Missing atom in 0 entry in _chem_comp_bond"
92+ ]
93+ assert mol .GetNumBonds () == 0
0 commit comments