diff --git a/translate2modelcif.py b/translate2modelcif.py index 4e9e9b2620a8c3d8058ad0fecd39f7f3b3da0be8..25acfc101b2662dc016e7a7b28ce7231c5c99627 100644 --- a/translate2modelcif.py +++ b/translate2modelcif.py @@ -219,7 +219,7 @@ def _get_audit_authors(): return ("Foo B", "Bar F") -def _get_protocol_steps_and_software(trg_ents): +def _get_protocol_steps_and_software(): """Create the list of protocol steps with software and parameters used.""" protocol = [] @@ -476,11 +476,63 @@ def _get_modelcif_entities(target_ents, source, asym_units, system): system.target_entities.append(mdlcif_ent) +def _get_modelcif_protocol(protocol_steps, target_entities, model): + """Create the protocol for the ModelCIF file.""" + protocol = modelcif.protocol.Protocol() + for js_step in protocol_steps: + sftwre = None + # ToDo [input]: Turn into software group if parameters are available + # ToDo [input]: Get software.description + # ToDo [input]: Get software.version + if js_step["software"]: + sftwre = modelcif.Software( + js_step["software"]["name"], + js_step["software"]["classification"], + js_step["software"]["description"], + js_step["software"]["location"], + js_step["software"]["type"], + js_step["software"]["version"], + citation=ihm.Citation( + pmid=js_step["software"]["citation"]["pmid"], + title=js_step["software"]["citation"]["title"], + journal=js_step["software"]["citation"]["journal"], + volume=js_step["software"]["citation"]["volume"], + page_range=js_step["software"]["citation"]["page_range"], + year=js_step["software"]["citation"]["year"], + authors=js_step["software"]["citation"]["authors"], + doi=js_step["software"]["citation"]["doi"], + ), + ) + if js_step["input"] == "target_sequences": + input_data = modelcif.data.DataGroup(target_entities) + elif js_step["input"] == "model": + input_data = model + else: + raise RuntimeError(f"Unknown protocol input: '{js_step['input']}'") + if js_step["output"] == "model": + output_data = model + else: + raise RuntimeError( + f"Unknown protocol output: '{js_step['output']}'" + ) + protocol.steps.append( + modelcif.protocol.Step( + input_data=input_data, + output_data=output_data, + name=js_step["name"], + details=js_step["details"], + software=sftwre, + ) + ) + protocol.steps[-1].method_type = js_step["method_type"] + + return protocol + + def _store_as_modelcif(interaction_name, data_json, ost_ent, file_prfx): """Mix all the data into a ModelCIF file.""" print(" generating ModelCIF objects...", end="") pstart = timer() - # ToDo [internal]: Get protocol/ software # create system to gather all the data system = modelcif.System( title=data_json["title"], @@ -530,54 +582,9 @@ def _store_as_modelcif(interaction_name, data_json, ost_ent, file_prfx): ) system.model_groups.append(model_group) - # Add protocol - protocol = modelcif.protocol.Protocol() - for js_step in data_json["protocol"]: - sftwre = None - # ToDo [input]: Turn into software group if parameters are available - # ToDo [input]: Get software.description - # ToDo [input]: Get software.version - if js_step["software"]: - sftwre = modelcif.Software( - js_step["software"]["name"], - js_step["software"]["classification"], - js_step["software"]["description"], - js_step["software"]["location"], - js_step["software"]["type"], - js_step["software"]["version"], - citation=ihm.Citation( - pmid=js_step["software"]["citation"]["pmid"], - title=js_step["software"]["citation"]["title"], - journal=js_step["software"]["citation"]["journal"], - volume=js_step["software"]["citation"]["volume"], - page_range=js_step["software"]["citation"]["page_range"], - year=js_step["software"]["citation"]["year"], - authors=js_step["software"]["citation"]["authors"], - doi=js_step["software"]["citation"]["doi"], - ), - ) - if js_step["input"] == "target_sequences": - input_data = modelcif.data.DataGroup(system.target_entities) - elif js_step["input"] == "model": - input_data = model - else: - raise RuntimeError(f"Unknown protocol input: '{js_step['input']}'") - if js_step["output"] == "model": - output_data = model - else: - raise RuntimeError( - f"Unknown protocol output: '{js_step['output']}'" - ) - protocol.steps.append( - modelcif.protocol.Step( - input_data=input_data, - output_data=output_data, - name=js_step["name"], - details=js_step["details"], - software=sftwre, - ) - ) - protocol.steps[-1].method_type = js_step["method_type"] + protocol = _get_modelcif_protocol( + data_json["protocol"], system.target_entities, model + ) system.protocols.append(protocol) # write modelcif System to file @@ -604,7 +611,7 @@ def _create_model_json(data, pdb_file, up_acs): """Create a dictionary (mimicking JSON) that contains all the data.""" data["target_entities"], ost_ent = _get_entities(pdb_file, up_acs) - data["protocol"] = _get_protocol_steps_and_software(data["target_entities"]) + data["protocol"] = _get_protocol_steps_and_software() return ost_ent