Skip to content

Commit

Permalink
Remove special handling for target entities
Browse files Browse the repository at this point in the history
Since we no longer create Entities for templates,
all entities are "target" entities, so there is no
need to keep a separate list for these.
  • Loading branch information
benmwebb committed Apr 19, 2024
1 parent 3c97151 commit c065c3d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 44 deletions.
15 changes: 2 additions & 13 deletions modelcif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def __init__(self, title=None, id='model', database=None,

self.entities = []
self.asym_units = []
self.target_entities = []
self.templates = []
self.template_segments = []
self.template_transformations = []
Expand Down Expand Up @@ -109,8 +108,6 @@ def _before_write(self):
self.entities = list(_remove_identical(self._all_entities()))
self.template_transformations = list(_remove_identical(
self._all_template_transformations()))
self.target_entities = list(_remove_identical(
self._all_target_entities()))
self.data_groups = list(_remove_identical(
self._all_data_groups()))
self.data = list(_remove_identical(
Expand All @@ -124,7 +121,7 @@ def _before_write(self):

def _add_missing_reference_sequence(self):
"""If any TargetReference has no sequence, use that of the Entity"""
for e in self.entities + self.target_entities:
for e in self.entities:
for r in e.references:
if r.sequence is None:
r.sequence = "".join(comp.code_canonical
Expand Down Expand Up @@ -160,13 +157,6 @@ def _all_citations(self):
(software.citation for software in self._all_software()
if software.citation)))

def _all_target_entities(self):
"""Iterate over all Entities that are used for targets rather than
templates."""
return (itertools.chain(
self.target_entities,
(asym.entity for asmb in self.assemblies for asym in asmb)))

def _all_software(self):
"""Utility method used by ihm.dumper to get all Software. To initially
populate this list from all Software referenced in the system,
Expand Down Expand Up @@ -223,7 +213,6 @@ def _all_asym_in_assemblies():
self.asym_units, _all_asym_in_assemblies())

def _all_entities(self):
# Note that template entities are not included by default
return itertools.chain(
self.entities,
(asym.entity for asym in self.asym_units))
Expand All @@ -250,7 +239,7 @@ def _all_data_in_files():
return itertools.chain(
self.data,
self.templates,
self.target_entities,
self.entities,
self.alignments,
(model for group, model in self._all_models()),
_all_data_in_groups(),
Expand Down
10 changes: 2 additions & 8 deletions modelcif/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ def dump(self, system, writer):

class _TargetRefDBDumper(Dumper):
def dump(self, system, writer):
# Since target_entities is a *subset* of all entities, they may not
# be ordered by ID. Sort them so the output is prettier.
entities = sorted(system.target_entities,
key=operator.attrgetter('_id'))
with writer.loop(
"_ma_target_ref_db_details",
["target_entity_id", "db_name", "db_name_other_details",
Expand All @@ -115,7 +111,7 @@ def dump(self, system, writer):
"ncbi_taxonomy_id", "organism_scientific",
"seq_db_sequence_version_date",
"seq_db_sequence_checksum"]) as lp:
for e in entities:
for e in system.entities:
for r in e.references:
if r.align_begin is None:
db_begin = min(a.db_begin for a in r._get_alignments())
Expand Down Expand Up @@ -167,12 +163,10 @@ def dump(self, system, writer):

class _TargetEntityDumper(Dumper):
def dump(self, system, writer):
entities = sorted(system.target_entities,
key=operator.attrgetter('_id'))
with writer.loop(
"_ma_target_entity",
["entity_id", "data_id", "origin"]) as lp:
for e in entities:
for e in system.entities:
lp.write(entity_id=e._id, data_id=e._data_id,
origin="reference database" if e.references
else "designed")
Expand Down
8 changes: 4 additions & 4 deletions test/test_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_data_dumper(self):
"""Test DataDumper"""
system = modelcif.System()
entity = modelcif.Entity("DMA", description='test entity')
system.target_entities.append(entity)
system.entities.append(entity)
# Template and target use same entity here (but different data IDs)
template = modelcif.Template(
entity, asym_id="A", model_num=1, name="test template",
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_data_group_dumper(self):
tgt_e1._data_id = 1
tgt_e2._data_id = 2
tgt_e3._data_id = 3
system.target_entities.extend((tgt_e1, tgt_e2, tgt_e3))
system.entities.extend((tgt_e1, tgt_e2, tgt_e3))
dg12 = modelcif.data.DataGroup((tgt_e1, tgt_e2))
p = modelcif.protocol.Protocol()
p.steps.append(modelcif.protocol.ModelingStep(
Expand Down Expand Up @@ -516,7 +516,7 @@ class CustomRef(modelcif.reference.TargetReference):

e1 = modelcif.Entity('ACGT', references=[ref1, ref2, ref3, ref4, ref5])
e1._id = 1
system.target_entities.append(e1)
system.entities.append(e1)

dumper = modelcif.dumper._TargetRefDBDumper()
dumper.finalize(system)
Expand Down Expand Up @@ -844,7 +844,7 @@ def test_target_entity_dumper(self):
e1 = modelcif.Entity("D")
e1._id = 42
e1._data_id = 99
system.target_entities.append(e1)
system.entities.append(e1)

a1 = modelcif.AsymUnit(e1, 'foo')
a1._id = 'X'
Expand Down
20 changes: 1 addition & 19 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_all_data(self):
s = modelcif.System()
e1 = modelcif.Entity("D")
e2 = modelcif.Entity("M")
s.target_entities.extend((e1, e2))
s.entities.extend((e1, e2))

e3 = modelcif.Entity("A")
s.data.extend((e1, e3))
Expand Down Expand Up @@ -86,24 +86,6 @@ def test_all_data_groups(self):
d = s._all_data_groups()
self.assertEqual(list(d), [e1, e1, e2])

def test_all_target_entities(self):
"""Test _all_target_entities() method"""
s = modelcif.System()
e1 = modelcif.Entity("D")
e2 = modelcif.Entity("M")
s.target_entities.extend((e1, e2))

template_e = modelcif.Entity("M")
s.entities.extend((e1, e2, template_e))

asym = modelcif.AsymUnit(e1, 'foo')
s.asym_units.append(asym)
s.assemblies.append(modelcif.Assembly((asym,)))

te = s._all_target_entities()
# List may contain duplicates, but no template entities
self.assertEqual(list(te), [e1, e2, e1])

def test_all_template_transformations(self):
"""Test _all_template_transformations() method"""
s = modelcif.System()
Expand Down

0 comments on commit c065c3d

Please sign in to comment.