Skip to content

Commit d45286f

Browse files
committed
Fill in formula_weight from CCD info if requested
1 parent 6cc2301 commit d45286f

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

ihm/util/make_mmcif.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ class _ChemCompHandler:
305305
"""Read the _chem_comp table from a CCD entry"""
306306
not_in_file = omitted = unknown = None
307307

308-
def __call__(self, name, type, formula):
308+
def __call__(self, name, type, formula, formula_weight: float):
309309
self.name, self.type, self.formula = name, type, formula
310+
self.formula_weight = formula_weight
310311

311312

312313
def _fix_incomplete_chem_comps(s):
@@ -329,6 +330,7 @@ def _fix_chem_comp(cc, typmap):
329330
if hasattr(h, 'name') and h.name is not None:
330331
cc.name = h.name
331332
cc.formula = h.formula
333+
cc.formula_weight = h.formula_weight
332334
cc.__class__ = typmap.get(h.type.lower(), ihm.ChemComp)
333335

334336

test/mock/non_canon_atom/urllib/request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
zinc_atoms = b'_chem_comp_atom.comp_id ZN\n_chem_comp_atom.atom_id ZN\n'
55

6+
# The weight for MG here is deliberately wrong to ensure that we use
7+
# this CCD info and not the element mass
68
mg = b"""
79
_chem_comp.id MG
810
_chem_comp.name "MAGNESIUM ION"
911
_chem_comp.type NON-POLYMER
1012
_chem_comp.pdbx_type HETAI
1113
_chem_comp.formula Mg
14+
_chem_comp.formula_weight 26.305
1215
"""
1316

1417
uniprot_fasta = b""">tr|Q90VU7|Q90VU7_HV1 Protein Nef

test/test_make_mmcif.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,12 @@ def test_missing_chem_comp(self):
377377
with open('output.cif') as fh:
378378
contents = fh.readlines()
379379
ind = contents.index('_chem_comp.formula_weight\n')
380+
# Note that the mass for MG in our mock CCD is deliberately wrong
381+
# (26, not 24) to ensure that we use it instead of the element mass
380382
self.assertEqual(
381383
contents[ind + 1:ind + 5],
382384
["ALA 'L-peptide linking' ALANINE 'C3 H7 N O2' 89.094\n",
383-
"MG non-polymer 'MAGNESIUM ION' Mg 24.305\n",
385+
"MG non-polymer 'MAGNESIUM ION' Mg 26.305\n",
384386
'ZN other . . .\n',
385387
'invalid-chem-comp other . . .\n'])
386388
os.unlink('output.cif')

0 commit comments

Comments
 (0)