Example #1
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)
Example #2
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)
Example #3
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
Example #4
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))
Example #5
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))
Example #6
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))
Example #7
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)
Example #8
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)
Example #9
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
Example #10
0
    def _get_seq_id_range_all_templates(self):
        """Get the seq_id range covered by all templates in this starting
           model, as an AsymUnit or AsymUnitRange object. Where there are
           multiple templates, consolidate them; template info is given in
           starting_comparative_models."""
        def get_seq_id_range(template, full):
            # The template may cover more than the current starting model
            rng = template.seq_id_range
            return (max(rng[0] + self.offset,
                        full[0]), min(rng[1] + self.offset, full[1]))

        if self.templates:
            full = self.asym_unit.seq_id_range
            rng = get_seq_id_range(self.templates[0], full)
            for template in self.templates[1:]:
                this_rng = get_seq_id_range(template, full)
                rng = (min(rng[0], this_rng[0]), max(rng[1], this_rng[1]))
            return ihm.AsymUnit(self.asym_unit.entity)(*rng)
        else:
            return self.asym_unit
Example #11
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])
Example #12
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)
Example #13
0
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
# two subassemblies (of the subunits) that the SAXS data applies to:
modeled_assembly = ihm.Assembly((asymA, asymB), name='Modeled assembly')
assemblyA = ihm.Assembly((asymA, ), name='Subunit A')
assemblyB = ihm.Assembly((asymB, ), name='Subunit B')

# Define how the system was represented. Multiple representations of the
# system are possible, and can overlap. Here we'll say we represent A
# atomically as a rigid body and B as 3 flexible coarse-grained spheres:
rep = ihm.representation.Representation([
    ihm.representation.AtomicSegment(asymA, rigid=True),
Example #14
0
# 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
entity_h2o = ihm.Entity([ihm.WaterChemComp()], description='Water')

system.entities.extend(
    (entity_protein, entity_rna, entity_dna, entity_heme, entity_h2o))

# Next, we define asymmetric units for everything we modeled.
# Here, we have a single instance of each protein, RNA and DNA, two hemes,
# plus crystal waters
asym_protein = ihm.AsymUnit(entity_protein, details='Subunit A')
asym_rna = ihm.AsymUnit(entity_rna, details='RNA chain')
asym_dna = ihm.AsymUnit(entity_dna, details='DNA chain')
asym_heme1 = ihm.AsymUnit(entity_heme, details='First heme')
asym_heme2 = ihm.AsymUnit(entity_heme, details='Second heme')
asym_h2o = ihm.AsymUnit(entity_h2o, details='Crystal waters')
system.asym_units.extend(
    (asym_protein, asym_rna, asym_dna, asym_heme1, asym_heme2, asym_h2o))

# todo: show handling of multiple waters

# Once the system is complete, we can write it out to an mmCIF file:
with open('output.cif', 'w') as fh:
    ihm.dumper.write(fh, [system])