Esempio n. 1
0
 def test_entity_weight(self):
     """Test Entity.formula_weight"""
     e1 = ihm.Entity('AHCD')
     self.assertAlmostEqual(e1.formula_weight, 499.516, places=1)
     # Entity containing a component with unknown weight
     heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
     self.assertIsNone(heme.formula_weight)
Esempio n. 2
0
    def test_entity_type(self):
        """Test Entity.type"""
        protein = ihm.Entity('AHCD')
        heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
        water = ihm.Entity([ihm.WaterChemComp()])
        self.assertEqual(protein.type, 'polymer')
        self.assertTrue(protein.is_polymeric())
        self.assertEqual(heme.type, 'non-polymer')
        self.assertFalse(heme.is_polymeric())
        self.assertEqual(water.type, 'water')
        self.assertFalse(water.is_polymeric())

        # A single amino acid should be classified non-polymer
        single_aa = ihm.Entity('A')
        self.assertEqual(single_aa.type, 'non-polymer')
        self.assertFalse(single_aa.is_polymeric())

        # ... unless forced polymer
        single_aa._force_polymer = True
        self.assertEqual(single_aa.type, 'polymer')
        self.assertTrue(single_aa.is_polymeric())

        # An entity with no sequence is a polymer
        empty = ihm.Entity([])
        self.assertEqual(empty.type, 'polymer')
        self.assertTrue(empty.is_polymeric())
Esempio n. 3
0
 def test_assembly(self):
     """Test Assembly class"""
     e1 = ihm.Entity('AHCD')
     e2 = ihm.Entity('AHC')
     a = ihm.Assembly([e1, e2], name='foo', description='bar')
     self.assertEqual(a.name, 'foo')
     self.assertEqual(a.description, 'bar')
Esempio n. 4
0
    def test_entity_source(self):
        """Test setting Entity source"""
        man = ihm.Entity('AHCD', source=ihm.source.Manipulated())
        self.assertEqual(man.src_method, "man")

        nat = ihm.Entity('AHCD', source=ihm.source.Natural())
        self.assertEqual(nat.src_method, "nat")

        syn = ihm.Entity('AHCD', source=ihm.source.Synthetic())
        self.assertEqual(syn.src_method, "syn")
Esempio n. 5
0
 def test_entity_src_method_default(self):
     """Test default values of Entity.src_method"""
     protein = ihm.Entity('AHCD')
     water = ihm.Entity([ihm.WaterChemComp()])
     self.assertEqual(protein.src_method, "man")
     self.assertEqual(water.src_method, "nat")
     # src_method is readonly
     def try_set():
         protein.src_method = 'foo'
     self.assertRaises(TypeError, try_set)
Esempio n. 6
0
 def test_entity_type(self):
     """Test Entity.type"""
     protein = ihm.Entity('AHCD')
     heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
     water = ihm.Entity([ihm.WaterChemComp()])
     self.assertEqual(protein.type, 'polymer')
     self.assertTrue(protein.is_polymeric())
     self.assertEqual(heme.type, 'non-polymer')
     self.assertFalse(heme.is_polymeric())
     self.assertEqual(water.type, 'water')
     self.assertFalse(water.is_polymeric())
Esempio n. 7
0
 def test_component_mapper_same_id_chain(self):
     """Test ComponentMapper given two chains with same ID"""
     system = ihm.System()
     cm = IMP.mmcif.data._ComponentMapper(system)
     entity1 = ihm.Entity("ANC")
     entity2 = ihm.Entity("DEF")
     chain1 = MockChain("A")
     chain2 = MockChain("A")
     comp1 = cm.add(chain1, entity1)
     self.assertEqual(cm[chain1], comp1)
     # Cannot add two chains with the same ID but different sequences
     self.assertRaises(ValueError, cm.add, chain2, entity2)
Esempio n. 8
0
 def test_component_mapper_get_all(self):
     """Test ComponentMapper get_all()"""
     system = ihm.System()
     cm = IMP.mmcif.data._ComponentMapper(system)
     entity1 = ihm.Entity("ANC")
     entity2 = ihm.Entity("DEF")
     chain1 = MockChain("A")
     chain2 = MockChain("B")
     comp1 = cm.add(chain1, entity1)
     comp2 = cm.add(chain2, entity2)
     allc = cm.get_all()
     self.assertEqual(allc, [comp1, comp2])
     self.assertEqual(cm.get_all_modeled(), [])
Esempio n. 9
0
 def test_entity(self):
     """Test Entity class"""
     e1 = ihm.Entity('AHCD', description='foo')
     # Should compare identical if sequences are the same
     e2 = ihm.Entity('AHCD', description='bar')
     e3 = ihm.Entity('AHCDE', description='foo')
     heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
     self.assertEqual(e1, e2)
     self.assertNotEqual(e1, e3)
     self.assertEqual(e1.seq_id_range, (1, 4))
     self.assertEqual(e3.seq_id_range, (1, 5))
     # seq_id does not exist for nonpolymers
     self.assertEqual(heme.seq_id_range, (None, None))
Esempio n. 10
0
 def test_atom(self):
     """Test Atom class"""
     e = ihm.Entity('AHCDAH')
     a = e.residue(3).atom('CA')
     self.assertEqual(a.id, 'CA')
     self.assertEqual(a.residue.entity, e)
     self.assertEqual(a.residue.seq_id, 3)
Esempio n. 11
0
def make_representation(system, cccp):
    """Using one of the output RMFs as a guide, create the IHM representation
       (i.e. the subunits in the system and how residues are represented
       as beads)."""
    fname = os.path.join('..', 'final_models_1x_Spc29',
                         'cluster_without_Spc29',
                         'cluster2.1/top_scoring_model.rmf')
    seqs = IMP.pmi.topology.Sequences(
        os.path.join('..', '..', 'inputs', 'shared_inputs', 'seqs.fasta'))
    ccdatasets = _get_starting_coiled_coil_datasets()

    # Mapping from RMF names of subunits to ihm.Entity objects
    entities_by_name = {}
    # Map from localization density filename to list of asym ranges
    density_map = {}
    rep = ihm.representation.Representation()

    m = IMP.Model()
    rh = RMF.open_rmf_file_read_only(fname)
    hs = IMP.rmf.create_hierarchies(rh, m)
    for h in hs:
        name = h.get_name()
        entity_name = 'GFP' if name.endswith('GFP') else name
        if entity_name not in entities_by_name:
            e = ihm.Entity(seqs[entity_name], description=entity_name)
            system.entities.append(e)
            entities_by_name[entity_name] = e
        asym = ihm.AsymUnit(entities_by_name[entity_name], details=name)
        system.asym_units.append(asym)
        _add_asym_representation(h, asym, rep, ccdatasets, cccp)
        _add_density_map(h, asym, density_map)

    system.orphan_representations.append(rep)
    return entities_by_name, rep, density_map
Esempio n. 12
0
 def test_auth_seq_id_dict(self):
     """Test auth_seq_id dict map from seq_id"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map={1: 0, 2: (4, 'A')})
     self.assertEqual(a._get_auth_seq_id_ins_code(1), (0, None))
     self.assertEqual(a._get_auth_seq_id_ins_code(2), (4, 'A'))
     self.assertEqual(a._get_auth_seq_id_ins_code(3), (3, None))
Esempio n. 13
0
 def test_auth_seq_id_list(self):
     """Test auth_seq_id list map from seq_id"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map=[None, 0, 4])
     self.assertEqual(a._get_auth_seq_id(1), 0)
     self.assertEqual(a._get_auth_seq_id(2), 4)
     self.assertEqual(a._get_auth_seq_id(3), 3)
Esempio n. 14
0
 def test_entity_residue(self):
     """Test Residue derived from an Entity"""
     e = ihm.Entity('AHCDAH')
     r = e.residue(3)
     self.assertEqual(r.entity, e)
     self.assertIsNone(r.asym)
     self.assertEqual(r.seq_id, 3)
Esempio n. 15
0
 def test_auth_seq_id_dict(self):
     """Test auth_seq_id dict map from seq_id"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map={1: 0, 2: 4})
     self.assertEqual(a._get_auth_seq_id(1), 0)
     self.assertEqual(a._get_auth_seq_id(2), 4)
     self.assertEqual(a._get_auth_seq_id(3), 3)
Esempio n. 16
0
 def test_auth_seq_id_list(self):
     """Test auth_seq_id list map from seq_id"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map=[None, 0, 4])
     self.assertEqual(a._get_auth_seq_id_ins_code(1), (0, None))
     self.assertEqual(a._get_auth_seq_id_ins_code(2), (4, None))
     self.assertEqual(a._get_auth_seq_id_ins_code(3), (3, None))
Esempio n. 17
0
 def test_asym_segment(self):
     """Test AsymUnitSegment class"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e)
     seg = a.segment('AH--CD', 1, 4)
     self.assertEqual(seg.gapped_sequence, 'AH--CD')
     self.assertEqual(seg.seq_id_range, (1, 4))
Esempio n. 18
0
 def test_entity_range(self):
     """Test EntityRange class"""
     e = ihm.Entity('AHCDAH')
     heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
     e._id = 42
     self.assertEqual(e.seq_id_range, (1, 6))
     r = e(3, 4)
     self.assertEqual(r.seq_id_range, (3, 4))
     self.assertEqual(r._id, 42)
     # Cannot create ranges for nonpolymeric entities
     self.assertRaises(TypeError, heme.__call__, 1, 1)
     samer = e(3, 4)
     otherr = e(2, 4)
     self.assertEqual(r, samer)
     self.assertEqual(hash(r), hash(samer))
     self.assertNotEqual(r, otherr)
     self.assertNotEqual(r, e)  # entity_range != entity
Esempio n. 19
0
 def test_asym_unit_residue(self):
     """Test Residue derived from an AsymUnit"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map=5)
     r = a.residue(3)
     self.assertIsNone(r.entity)
     self.assertEqual(r.asym, a)
     self.assertEqual(r.seq_id, 3)
     self.assertEqual(r.auth_seq_id, 8)
Esempio n. 20
0
 def test_atom_asym(self):
     """Test Atom class built from an AsymUnit"""
     e = ihm.Entity('AHCDAH')
     asym = ihm.AsymUnit(e)
     a = asym.residue(3).atom('CA')
     self.assertEqual(a.id, 'CA')
     self.assertEqual(a.residue.seq_id, 3)
     self.assertIsNone(a.entity)
     self.assertEqual(a.asym, asym)
     self.assertEqual(a.seq_id, 3)
Esempio n. 21
0
 def test_atom_entity(self):
     """Test Atom class built from an Entity"""
     e = ihm.Entity('AHCDAH')
     a = e.residue(3).atom('CA')
     self.assertEqual(a.id, 'CA')
     self.assertEqual(a.residue.entity, e)
     self.assertEqual(a.residue.seq_id, 3)
     self.assertEqual(a.entity, e)
     self.assertIsNone(a.asym)
     self.assertEqual(a.seq_id, 3)
Esempio n. 22
0
 def test_entity_naming(self):
     """Test naming of Entities"""
     system = ihm.System()
     cm = IMP.mmcif.data._ComponentMapper(system)
     entity1 = ihm.Entity("ANC")
     chain1 = MockChain("A.1@12")
     chain2 = MockChain("A.2@12")
     comp1 = cm.add(chain1, entity1)
     comp2 = cm.add(chain2, entity1)
     self.assertEqual(chain1.name, "A.1@12")
     self.assertEqual(chain2.name, "A.2@12")
     self.assertEqual(entity1.description, 'A')
Esempio n. 23
0
 def test_asym_range(self):
     """Test AsymUnitRange class"""
     e = ihm.Entity('AHCDAH')
     heme = ihm.Entity([ihm.NonPolymerChemComp('HEM')])
     a = ihm.AsymUnit(e)
     aheme = ihm.AsymUnit(heme)
     a._id = 42
     self.assertEqual(a.seq_id_range, (1, 6))
     # seq_id is not defined for nonpolymers
     self.assertEqual(aheme.seq_id_range, (None, None))
     r = a(3, 4)
     self.assertEqual(r.seq_id_range, (3, 4))
     self.assertEqual(r._id, 42)
     self.assertEqual(r.entity, e)
     # Cannot create ranges for nonpolymeric entities
     self.assertRaises(TypeError, aheme.__call__, 1, 1)
     samer = a(3, 4)
     otherr = a(2, 4)
     self.assertEqual(r, samer)
     self.assertEqual(hash(r), hash(samer))
     self.assertNotEqual(r, otherr)
     self.assertNotEqual(r, a)  # asym_range != asym
     self.assertNotEqual(r, e(3, 4))  # asym_range != entity_range
     self.assertNotEqual(r, e)  # asym_range != entity
Esempio n. 24
0
    def test_all_entity_ranges(self):
        """Test _all_entity_ranges() method"""
        class MockObject(object):
            pass

        s = ihm.System()
        e1 = ihm.Entity('AHCD', description='foo')
        a1 = ihm.AsymUnit(e1)
        s.entities.append(e1)
        s.asym_units.append(a1)
        e1rng = e1(1, 3)
        a1rng = a1(1, 2)

        sm1 = MockObject()
        sm1.asym_unit = e1rng
        s.orphan_starting_models.append(sm1)

        rep = ihm.representation.Representation()
        seg1 = ihm.representation.Segment()
        seg1.starting_model = None
        seg1.asym_unit = a1
        rep.append(seg1)
        s.orphan_representations.append(rep)

        asmb1 = ihm.Assembly([e1, a1])
        s.orphan_assemblies.append(asmb1)

        ensemble = MockObject()
        density = MockObject()
        density.asym_unit = a1rng
        ensemble.densities = [density]
        s.ensembles.append(ensemble)

        # duplicates should not be filtered
        self.assertEqual(list(s._all_entity_ranges()),
                         [e1rng, a1, e1, a1, a1rng])
Esempio n. 25
0
 def test_auth_seq_id_offset(self):
     """Test auth_seq_id offset from seq_id"""
     e = ihm.Entity('AHCDAH')
     a = ihm.AsymUnit(e, auth_seq_id_map=5)
     self.assertEqual(a._get_auth_seq_id(1), 6)
Esempio n. 26
0
# This example demonstrates how non-polymeric entities (ligands, water)
# are handled by the Python IHM library. See the simple-docking.py example
# for an introduction to the library.

import ihm
import ihm.dumper

system = ihm.System()

# An entity corresponding to an amino acid (polyalanine) sequence
entity_protein = ihm.Entity('AAA', description='Subunit A')

# An entity corresponding to an RNA sequence
entity_rna = ihm.Entity('ACG',
                        alphabet=ihm.RNAAlphabet,
                        description='RNA chain')

# An entity corresponding to a DNA sequence
entity_dna = ihm.Entity(['DA', 'DC', 'DG'],
                        alphabet=ihm.DNAAlphabet,
                        description='DNA chain')

# Non-polymers such as ligands or water should each live in their own Entity:

# A ligand entity (in this case, heme)
heme = ihm.NonPolymerChemComp("HEM",
                              name='PROTOPORPHYRIN IX CONTAINING FE',
                              formula='C34 H32 Fe N4 O4')
entity_heme = ihm.Entity([heme], description='Heme')

# Water
Esempio n. 27
0
# here we define it in its L- form using the LPeptideChemComp class.
#
# 'id' should match the officially defined name of the component, as defined
#     in the chemical component dictionary: https://www.wwpdb.org/data/ccd
#     (See also https://www3.rcsb.org/ligand/NVA)
# 'code' is used to populate the primary sequence in the output mmCIF file.
#     For non-standard residues it should normally match 'id'.
# 'code_canonical' is the the one-letter code of the closest standard residue.
#     Here we use 'V', valine.
norvaline = ihm.LPeptideChemComp(id='NVA', code='NVA', code_canonical='V',
                                 name='NORVALINE', formula='C5 H11 N O2')

# The Entity constructor takes a sequence of either or both one-letter codes
# and ChemComp objects, so now we can make a sequence containing both
# alanine and norvaline:
entity1 = ihm.Entity(['A', 'A', norvaline, 'A'], description='First entity')

# If a particular non-standard residue is commonly used in your own software,
# and you have assigned a one-letter code for it, you can subclass
# the ihm Alphabet class appropriately. Here we extend the normal set of
# one-letter codes (uppercase) for standard L- amino acids to add 'n' for
# norvaline:

class MyAlphabet(ihm.LPeptideAlphabet):
    # Alphabet contains a _comps dictionary that is a simple mapping from
    # codes (usually one-letter) to ChemComp objects
    _comps = {}
    _comps.update(ihm.LPeptideAlphabet._comps)
    _comps['n'] = norvaline

# Now we can pass a primary sequence using our custom alphabet to include
Esempio n. 28
0
# say lives in the EMDB database:
loc = ihm.location.EMDBLocation('EMDB-1234')
em_dataset = ihm.dataset.EMDensityDataset(loc)
# We also used two SAXS profiles, which we'll say live in SASBDB:
saxsA_dataset = ihm.dataset.SASDataset(ihm.location.SASBDBLocation('SASDB123'))
saxsB_dataset = ihm.dataset.SASDataset(ihm.location.SASBDBLocation('SASDB456'))

# Where datasets are derived from some other data, it is helpful to also point
# back to that primary data. In this case, let's say the EM density was
# derived from a set of EM micrographs, deposited in the EMPIAR database:
m = ihm.dataset.EMMicrographsDataset(ihm.location.EMPIARLocation('EMPIAR-123'))
em_dataset.parents.append(m)

# Next, define the entities for each unique sequence in the system
# (here represented as polyalanines):
entityA = ihm.Entity('AAA', description='Subunit A')
entityB = ihm.Entity('AAAAAA', description='Subunit B')
system.entities.extend((entityA, entityB))

# Next, we define asymmetric units for everything we modeled.
# These roughly correspond to chains in a traditional PDB file. Multiple
# asymmetric units may map to the same entity (for example if there are
# several copies of a given protein). Parts of the system that were seen in
# an experiment but were not modeled are represented as entities to which no
# asymmetric units map.
asymA = ihm.AsymUnit(entityA, details='Subunit A')
asymB = ihm.AsymUnit(entityB, details='Subunit B')
system.asym_units.extend((asymA, asymB))

# Next, we group asymmetric units (and/or entities) into assemblies.
# Here, we'll define an assembly of everything that we modeled, plus