def test_all_citations(self): """Test _all_citations() method""" class MockObject(object): pass c1 = ihm.Citation(title='Test paper', journal='J Mol Biol', volume=45, page_range=(1, 20), year=2016, authors=['Smith A', 'Jones B'], doi='10.2345/S1384107697000225', pmid='1234') c2 = ihm.Citation(title='Test paper', journal='J Mol Biol', volume=45, page_range=(1, 20), year=2016, authors=['Smith A', 'Jones B'], doi='1.2.3.4', pmid='1234') rsr1 = MockObject() # Not a 3dem restraint rsr2 = MockObject() # 3dem but with no provided citation rsr2.fitting_method_citation_id = None rsr3 = MockObject() rsr2.fitting_method_citation_id = c1 s = ihm.System() s.restraints.extend((rsr1, rsr2, rsr3)) s.citations.extend((c2, c2)) # duplicates should be filtered globally self.assertEqual(list(s._all_citations()), [c2, c1])
def test_all_pseudo_sites(self): """Test _all_pseudo_sites() method""" class MockObject(object): pass s1 = MockObject() s2 = MockObject() r1 = MockObject() xl = MockObject() ps = MockObject() ps.site = s2 xl.pseudo1 = [ps] xl.pseudo2 = None r1.cross_links = [xl] r2 = MockObject() xl = MockObject() xl.pseudo1 = None ps = MockObject() ps.site = s1 xl.pseudo2 = [ps] r2.cross_links = [xl] s = ihm.System() s.orphan_pseudo_sites.extend((s1, s2)) s.restraints.extend((r1, r2)) f1 = MockObject() f1.site = s2 s.orphan_features.append(f1) # duplicates should not be filtered self.assertEqual(list(s._all_pseudo_sites()), [s1, s2, s2, s1, s2])
def test_all_dataset_groups(self): """Test _all_dataset_groups() method""" class MockObject(object): pass dg1 = MockObject() dg2 = MockObject() s = ihm.System() s.orphan_dataset_groups.append(dg1) step1 = MockObject() step2 = MockObject() step3 = MockObject() step1.dataset_group = None step2.dataset_group = dg2 step3.dataset_group = dg1 protocol1 = MockObject() protocol1.steps = [step1, step2, step3] analysis1 = MockObject() astep1 = MockObject() astep1.dataset_group = dg2 analysis1.steps = [astep1] protocol1.analyses = [analysis1] s.orphan_protocols.append(protocol1) # duplicates should not be filtered self.assertEqual(list(s._all_dataset_groups()), [dg1, dg2, dg1, dg2])
def test_all_chem_descriptors(self): """Test _all_chem_descriptors() method""" class MockObject(object): pass d1 = ihm.ChemDescriptor("d1") d2 = ihm.ChemDescriptor("d2") d3 = ihm.ChemDescriptor("d3") d4 = ihm.ChemDescriptor("d4") s = ihm.System() f = ihm.flr.FLRData() s.flr_data.append(f) r1 = MockObject() r2 = MockObject() r2.linker = None r3 = MockObject() r2.linker = d3 s.restraints.extend((r1, r2)) r2.feature = None s.orphan_chem_descriptors.extend((d1, d2, d1)) # FLR chemical descriptors conj = ihm.flr.PolyProbeConjugate(sample_probe=None, chem_descriptor=d4, ambiguous_stoichiometry=False) f.poly_probe_conjugates.append(conj) # duplicates should not be filtered self.assertEqual(list(s._all_chem_descriptors()), [d1, d2, d1, d3, d4])
def test_update_locations_in_repositories(self): """Test update_locations_in_repositories() method""" s = ihm.System() loc = ihm.location.InputFileLocation(path='foo', repo='bar') s.locations.append(loc) r = ihm.location.Repository(doi='foo', root='..') s.update_locations_in_repositories([r])
def test_all_locations(self): """Test _all_locations() method""" class MockObject(object): pass class MockDataset(object): parents = [] loc1 = MockObject() loc2 = MockObject() loc3 = MockObject() s = ihm.System() dataset1 = MockDataset() dataset2 = MockDataset() dataset2.location = None dataset3 = MockDataset() dataset3.location = loc1 s.locations.append(loc1) s.orphan_datasets.extend((dataset1, dataset2, dataset3)) ensemble = MockObject() ensemble.file = loc2 density = MockObject() density.file = loc1 ensemble.densities = [density] s.ensembles.append(ensemble) start_model = MockObject() start_model.dataset = None start_model.script_file = loc2 template = MockObject() template.dataset = None template.alignment_file = loc3 start_model.templates = [template] s.orphan_starting_models.append(start_model) step1 = MockObject() step2 = MockObject() step1.dataset_group = None step2.dataset_group = None step1.script_file = None step2.script_file = loc2 protocol1 = MockObject() protocol1.steps = [step1, step2] analysis1 = MockObject() astep1 = MockObject() astep1.dataset_group = None astep1.script_file = loc2 analysis1.steps = [astep1] protocol1.analyses = [analysis1] s.orphan_protocols.append(protocol1) # duplicates should not be filtered self.assertEqual(list(s._all_locations()), [loc1, loc1, loc2, loc1, loc2, loc3, loc2, loc2])
def test_import(self): """Check that ihm package was installed""" import ihm import ihm.dataset import ihm.restraint import ihm.model import ihm.format # We should also have the C-accelerated tokenizer self.assertTrue(ihm.format._format is not None) s = ihm.System()
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)
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')
def test_all_citations(self): """Test _all_citations() method""" class MockObject(object): pass c1 = ihm.Citation(title='Test paper', journal='J Mol Biol', volume=45, page_range=(1, 20), year=2016, authors=['Smith A', 'Jones B'], doi='10.2345/S1384107697000225', pmid='1234') c2 = ihm.Citation(title='Test paper', journal='J Mol Biol', volume=45, page_range=(1, 20), year=2016, authors=['Smith A', 'Jones B'], doi='1.2.3.4', pmid='1234') c3 = ihm.Citation(title='Test paper2', journal='J Mol Biol2', volume=46, page_range=(1, 20), year=2017, authors=['Smith A', 'Jones B'], doi='5.6.7.8', pmid='5678') rsr1 = MockObject() # Not a 3dem restraint rsr2 = MockObject() # 3dem but with no provided citation rsr2.fitting_method_citation_id = None rsr3 = MockObject() rsr2.fitting_method_citation_id = c1 s1 = ihm.Software(name='test', classification='test code', description='Some test program', version=1, location='http://test.org') s2 = ihm.Software(name='test', classification='test code', description='Some test program', version=1, location='http://test.org', citation=c3) s = ihm.System() s.restraints.extend((rsr1, rsr2, rsr3)) s.citations.extend((c2, c2)) s.software.extend((s1, s2)) # duplicates should be filtered globally self.assertEqual(list(s._all_citations()), [c2, c3, c1])
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(), [])
def test_all_model_groups(self): """Test _all_model_groups() method""" model_group1 = 'mg1' model_group2 = 'mg2' model_group3 = 'mg3' model_group4 = 'mg4' state1 = [model_group1, model_group2] state2 = [model_group2, model_group2] s = ihm.System() s.state_groups.append([state1, state2]) proc = ihm.model.OrderedProcess("time steps") edge = ihm.model.ProcessEdge(model_group1, model_group2) step = ihm.model.ProcessStep([edge], "Linear reaction") proc.steps.append(step) s.ordered_processes.append(proc) e1 = ihm.model.Ensemble(model_group=model_group3, num_models=10, post_process=None, name='cluster1', clustering_method='Hierarchical', clustering_feature='RMSD', precision=4.2) ss1 = ihm.model.Subsample(name='foo', num_models=1) ss2 = ihm.model.Subsample(name='foo', num_models=1, model_group=model_group4) e1.subsamples.extend((ss1, ss2)) s.ensembles.append(e1) # Ensemble without a model_group e2 = ihm.model.Ensemble(model_group=None, num_models=10, post_process=None, name='cluster1', clustering_method='Hierarchical', clustering_feature='RMSD', precision=4.2) s.ensembles.append(e2) mg = s._all_model_groups() # List may contain duplicates but only includes states self.assertEqual( list(mg), [model_group1, model_group2, model_group2, model_group2]) mg = s._all_model_groups(only_in_states=False) # List contains all model groups self.assertEqual(list(mg), [ model_group1, model_group2, model_group2, model_group2, model_group3, model_group4, model_group1, model_group2 ])
def test_all_models(self): """Test _all_models() method""" class MockModel(object): pass model1 = MockModel() model2 = MockModel() model_group1 = [model1, model2] model_group2 = [model1, model1] s = ihm.System() s.state_groups.append([[model_group1, model_group2]]) ms = s._all_models() models = [model for group, model in ms] # duplicates should be filtered within groups, but not between groups self.assertEqual(models, [model1, model2, model1])
def test_all_software(self): """Test _all_software() method""" class MockObject(object): pass s1 = ihm.Software(name='test', classification='test code', description='Some test program', version=1, location='http://test.org') s2 = ihm.Software(name='foo', classification='test code', description='Other test program', location='http://test2.org') sm1 = MockObject() sm1.software = None sm2 = MockObject() sm2.software = s1 s = ihm.System() s.orphan_starting_models.extend((sm1, sm2)) s.software.extend((s2, s2)) step1 = MockObject() step2 = MockObject() step1.software = None step2.software = s2 protocol1 = MockObject() protocol1.steps = [step1, step2] analysis1 = MockObject() astep1 = MockObject() astep1.software = s2 analysis1.steps = [astep1] protocol1.analyses = [analysis1] s.orphan_protocols.append(protocol1) r1 = MockObject() r2 = MockObject() r3 = MockObject() r2.software = None r3.software = s1 s.restraints.extend((r1, r2, r3)) # duplicates are kept self.assertEqual(list(s._all_software()), [s2, s2, s1, s2, s2, s1])
def test_all_representations(self): """Test _all_representations() method""" class MockObject(object): pass model1 = MockObject() model2 = MockObject() model3 = MockObject() model_group1 = [model1, model2, model3] s = ihm.System() s.state_groups.append([[model_group1]]) r1 = MockObject() r2 = MockObject() s.orphan_representations.append(r1) model1.representation = None model2.representation = r2 model3.representation = r1 # duplicates should be filtered globally self.assertEqual(list(s._all_representations()), [r1, r2])
def test_entity_mapper_add(self): """Test EntityMapper.add()""" system = ihm.System() e = IMP.mmcif.data._EntityMapper(system) self.assertEqual(len(e.get_all()), 0) chain1 = MockChain("A", sequence='ANC') chain2 = MockChain("B", sequence='ANC') e.add(chain1) e.add(chain2) # Identical sequences, so only one entity self.assertEqual(len(e.get_all()), 1) # Different sequences, so two entities chain3 = MockChain("C", sequence='ANCD') e.add(chain3) self.assertEqual(len(e.get_all()), 2) # Cannot add chains with no sequence chain4 = MockChain("D", sequence='') self.assertRaises(ValueError, e.add, chain4)
def test_all_protocols(self): """Test _all_protocols() method""" class MockObject(object): pass model1 = MockObject() model2 = MockObject() model3 = MockObject() model_group1 = [model1, model2, model3] s = ihm.System() s.state_groups.append([[model_group1]]) p1 = MockObject() p2 = MockObject() s.orphan_protocols.append(p1) model1.protocol = None model2.protocol = p2 model3.protocol = p1 # duplicates should be filtered globally self.assertEqual(list(s._all_protocols()), [p1, p2])
def test_all_datasets(self): """Test _all_datasets() method""" class MockObject(object): pass class MockDataset(object): parents = [] s = ihm.System() d1 = MockDataset() d2 = MockDataset() d3 = MockDataset() d4 = MockDataset() s.orphan_datasets.append(d1) dg1 = [d2] s.orphan_dataset_groups.append(dg1) start_model1 = MockObject() start_model1.dataset = None start_model2 = MockObject() start_model2.dataset = d3 template = MockObject() template.dataset = None start_model1.templates = [template] start_model2.templates = [] s.orphan_starting_models.extend((start_model1, start_model2)) rsr1 = MockObject() rsr1.dataset = d4 d4.parents = [d2] # Handle parent being a TransformedDataset trand = MockObject() trand.transform = None trand.dataset = d1 d2.parents = [trand] d1.parents = d3.parents = [] s.restraints.append(rsr1) # duplicates should not be filtered self.assertEqual(list(s._all_datasets()), [d1, d1, d2, d3, d1, d2, d4])
def test_all_features(self): """Test _all_features() method""" class MockObject(object): pass f1 = MockObject() f2 = MockObject() s = ihm.System() r1 = MockObject() r2 = MockObject() r2._all_features = (None, ) r3 = MockObject() r3._all_features = (f1, ) s.orphan_features.extend((f1, f2)) s.restraints.extend((r1, r2, r3)) # duplicates should not be filtered self.assertEqual(list(s._all_features()), [f1, f2, f1])
def test_all_starting_models(self): """Test _all_starting_models() method""" class MockObject(object): pass s = ihm.System() sm1 = MockObject() sm2 = MockObject() s.orphan_starting_models.append(sm1) rep = ihm.representation.Representation() seg1 = ihm.representation.Segment() seg1.starting_model = None seg2 = ihm.representation.Segment() seg2.starting_model = sm2 seg3 = ihm.representation.Segment() seg3.starting_model = sm2 rep.extend((seg1, seg2, seg3)) s.orphan_representations.append(rep) # duplicates should be filtered self.assertEqual(list(s._all_starting_models()), [sm1, sm2])
def test_all_geometric_objects(self): """Test _all_geometric_objects() method""" class MockObject(object): pass geom1 = MockObject() geom2 = MockObject() s = ihm.System() r1 = MockObject() r2 = MockObject() r2.geometric_object = None r3 = MockObject() r3.geometric_object = geom1 s.orphan_geometric_objects.extend((geom1, geom2)) s.restraints.extend((r1, r2, r3)) # duplicates should not be filtered self.assertEqual(list(s._all_geometric_objects()), [geom1, geom2, geom1])
def test_all_assemblies(self): """Test _all_assemblies() method""" class MockObject(object): pass model1 = MockObject() model2 = MockObject() model_group1 = [model1, model2] s = ihm.System() s.state_groups.append([[model_group1]]) asmb1 = MockObject() asmb2 = MockObject() s.orphan_assemblies.append(asmb1) model1.assembly = None model1.protocol = None model2.assembly = asmb2 step = MockObject() step.assembly = asmb1 prot = MockObject() prot.steps = [step] analysis1 = MockObject() astep1 = MockObject() astep1.assembly = asmb2 analysis1.steps = [astep1] prot.analyses = [analysis1] model2.protocol = prot rsr1 = MockObject() rsr1.assembly = asmb2 rsr2 = MockObject() rsr2.assembly = None s.restraints.extend((rsr1, rsr2)) # duplicates should be present; complete assembly is always first self.assertEqual( list(s._all_assemblies()), [s.complete_assembly, asmb1, asmb2, asmb1, asmb2, asmb2])
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])
def __init__(self): self.system = ihm.System() self._external_files = IMP.mmcif.data._ExternalFiles(self.system) self.datasets = IMP.mmcif.data._Datasets(self.system) self._software = IMP.mmcif.data._AllSoftware(self.system)
import ihm import ihm.dumper import ihm.reader import os system = ihm.System(title='test system') entityA = ihm.Entity('AAA', description='Subunit A') entityB = ihm.Entity('AAAAAA', description='Subunit B') system.entities.extend((entityA, entityB)) # Test output in mmCIF and BinaryCIF formats with open('output.cif', 'w') as fh: ihm.dumper.write(fh, [system]) with open('output.bcif', 'wb') as fh: ihm.dumper.write(fh, [system], format='BCIF') # Make sure we can read back the files with open('output.cif') as fh: sys2, = ihm.reader.read(fh) assert sys2.title == 'test system' with open('output.bcif', 'rb') as fh: sys2, = ihm.reader.read(fh, format='BCIF') assert sys2.title == 'test system' os.unlink('output.cif') os.unlink('output.bcif')
def test_system(self): """Test System class""" s = ihm.System(title='test system') self.assertEqual(s.title, 'test system') self.assertEqual(s.id, 'model')
# docked together into a complex, AB, which is fitted against an electron # microscopy density map. import ihm import ihm.location import ihm.dataset import ihm.representation import ihm.restraint import ihm.protocol import ihm.model import ihm.dumper # First, we create a system, which contains everything we know about the # modeling. A single mmCIF file can contain multiple Systems, but in most # cases we use just one: system = ihm.System() # Next, we describe the input data we used, using dataset classes. # Each source of data has a location, such as a file on disk or a database # entry, and a type. In this example we used EM density data, which we'll # 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'))