Example #1
0
 def test_coef(self):
     h = Element('H')
     d = Element('D')
     cf = Element('Cf')
     es = Element('Es')
     self.assertIsNotNone(cf.it92)
     self.assertIsNotNone(cf.c4322)
     self.assertIsNone(es.it92)
     self.assertIsNone(es.c4322)
     self.assertEqual(h.it92.get_coefs(), d.it92.get_coefs())
     self.assertEqual(h.c4322.get_coefs(), d.c4322.get_coefs())
     self.assertEqual(Element('X').it92.get_coefs(), [0.0] * 9)
Example #2
0
def check_chem_comp_formula_weight(block):
    for cc in block.find('_chem_comp.', ['id', 'formula', 'formula_weight']):
        if cc.str(0) in ('UNX', 'UNL'):  # unknown residue or ligand
            continue
        fdict = formula_to_dict(cc.str(1).title())
        calc_weight = sum(n * Element(e).weight for (e, n) in fdict.items())
        diff = calc_weight - cif.as_number(cc[2])
        if not (abs(diff) < 0.1):  # also true if diff is NaN
            print('%s %s  %-16s % 9.3f - %9s = %+.3f' %
                  (block.name, cc[0], cc.str(1), calc_weight, cc[2], diff))
Example #3
0
 def test_name(self):
     for name in ELEMENT_MASS:
         el = Element(name)
         self.assertEqual(el.name, name)
     self.assertEqual(Element('AL').name, 'Al')
     self.assertEqual(Element('al').name, 'Al')
     # We check only the first two characters now.
     self.assertEqual(Element('alt').name, 'Al')
     self.assertEqual(Element('Q').name, 'X')
     self.assertEqual(Element('QQ').name, 'X')
     self.assertEqual(Element('--').name, 'X')
     self.assertEqual(Element('').name, 'X')
Example #4
0
#!/usr/bin/env python
# This script reads mmCIF file(s) and compares weights:
# * _entity.formula_weight with _entity_poly_seq and _chem_comp.formula_weight,
# * _chem_comp.formula_weight with _chem_comp.formula and atomic weights.

import os
import argparse
import collections
import itertools
from gemmi import cif, Element, expand_if_pdb_code

H2O_MASS = Element('O').weight + 2 * Element('H').weight
# but why PO2 and not PO3Hx?
PO2_MASS = Element('P').weight + 2 * Element('O').weight


# this function is also used in examples/monomers.py
def formula_to_dict(formula):
    '"O4 P -3" -> {O:4, P:1}'
    fdict = {}
    for elnum in formula.split():
        na = sum(e.isalpha() for e in elnum)
        if na == len(elnum):
            fdict[elnum] = 1
        elif na != 0:
            fdict[elnum[:na]] = int(elnum[na:])
    return fdict


def check_chem_comp_formula_weight(block):
    for cc in block.find('_chem_comp.', ['id', 'formula', 'formula_weight']):
Example #5
0
 def test_properties(self):
     self.assertEqual(Element('K').vdw_r, 2.75)
Example #6
0
 def test_atomic_number(self):
     self.assertEqual(Element('O').atomic_number, 8)
     self.assertEqual(Element('D').atomic_number, 1)
     self.assertEqual(Element('X').atomic_number, 0)
     for n in range(119):
         self.assertEqual(Element(n).atomic_number, n)
Example #7
0
 def test_weight(self):
     for name, mass in ELEMENT_MASS.items():
         self.assertAlmostEqual(Element(name).weight, mass, delta=1e-3)