Skip to content

Commit

Permalink
Resolves issues with missing outfile_prefix while processing CLC (#21)
Browse files Browse the repository at this point in the history
* added outfile_prefix to boundmolecule processing

* bumped version

---------

Co-authored-by: “roshan” <“[email protected]”>
  • Loading branch information
roshkjr and “roshan” authored Sep 11, 2023
1 parent 5879152 commit ad52113
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pdbeccdutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.1"
__version__ = "0.8.2"
41 changes: 27 additions & 14 deletions pdbeccdutils/scripts/boundmolecule_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,22 @@ def process_boundmolecules(self, pdb_id: str, output_dir: str):
clc_id = f"CLC_{i}"
component = clc_reader_result.component
component.id = clc_id
outfile_prefix = component.id
clc_out_dir = os.path.join(output_dir, component.id)
os.makedirs(clc_out_dir, exist_ok=True)
self.process_single_component(clc_reader_result, clc_out_dir)
self.process_single_component(
clc_reader_result, clc_out_dir, outfile_prefix
)

self._write_out_bm(pdb_id, bms, clc_reader_results, output_dir)
else:
raise EntryFailedException(f"Preprocessing of {pdb_id} failed")

def process_single_component(
self, clc_reader_result: clc_reader.CLCReaderResult, output_dir: str
self,
clc_reader_result: clc_reader.CLCReaderResult,
output_dir: str,
outfile_prefix: str,
):
"""Processes identified bound-molecules
* Checks components parsing and highlights issues encountered with the molecule
Expand All @@ -127,6 +133,7 @@ def process_single_component(
Args:
clc_reader_result: List of CLCReaderResult
output_dir: Path to ooutput directory
outfile_prefix: Prefix of output filename
"""
component = clc_reader_result.component
logging.info(f"{component.id} | processing...")
Expand All @@ -146,8 +153,8 @@ def process_single_component(
self._compute_component_scaffolds(component)

# write out files
self._generate_depictions(component, output_dir)
self._export_structure_formats(component, output_dir)
self._generate_depictions(component, output_dir, outfile_prefix)
self._export_structure_formats(component, output_dir, outfile_prefix)

def _write_out_bm(
self,
Expand Down Expand Up @@ -244,7 +251,9 @@ def _generate_ideal_structure(self, component: Component):

return result

def _generate_depictions(self, component: Component, out_dir: str):
def _generate_depictions(
self, component: Component, out_dir: str, outfile_prefix: str
):
"""Generate nice 2D depictions for the component and
depiction annotations in JSON format. Presently depictions
are generated in the following resolutions (100,200,300,400,500)
Expand All @@ -253,6 +262,7 @@ def _generate_depictions(self, component: Component, out_dir: str):
Args:
component (Component): Component to be depicted.
out_dir (str): Where the depictions should be stored.
outfile_prefix (str): Prefix of output filename
"""
depiction_result = component.compute_2d(self.depictions)

Expand All @@ -271,19 +281,19 @@ def _generate_depictions(self, component: Component, out_dir: str):

for i in range(100, 600, 100):
component.export_2d_svg(
os.path.join(out_dir, f"{component.id}_{i}.svg"),
os.path.join(out_dir, f"{outfile_prefix}_{i}.svg"),
width=i,
wedge_bonds=wedge_bonds,
)
component.export_2d_svg(
os.path.join(out_dir, f"{component.id}_{i}_names.svg"),
os.path.join(out_dir, f"{outfile_prefix}_{i}_names.svg"),
width=i,
names=True,
wedge_bonds=wedge_bonds,
)

component.export_2d_annotation(
os.path.join(out_dir, f"{component.id}_annotation.json"),
os.path.join(out_dir, f"{outfile_prefix}_annotation.json"),
wedge_bonds=wedge_bonds,
)

Expand Down Expand Up @@ -317,33 +327,36 @@ def _compute_component_scaffolds(self, component: Component):

logging.debug(f"{len(component.scaffolds)} scaffold(s) were found.")

def _export_structure_formats(self, component: Component, out_dir: str):
def _export_structure_formats(
self, component: Component, out_dir: str, outfile_prefix: str
):
"""Writes out component in a different formats as required for the
PDBeChem FTP area.
Args:
component (Component): Component being processed.
out_dir (Path): Where the results should be written
out_dir (Path): Where the results should be written.
outfile_prefix (str): Prefix of output filename
"""

self.__write_molecule(
os.path.join(out_dir, f"{component.id}_model.sdf"),
os.path.join(out_dir, f"{outfile_prefix}_model.sdf"),
component,
ConformerType.Model,
)

self.__write_molecule(
os.path.join(out_dir, f"{component.id}_model.pdb"),
os.path.join(out_dir, f"{outfile_prefix}_model.pdb"),
component,
ConformerType.Model,
)
self.__write_molecule(
os.path.join(out_dir, f"{component.id}.cml"),
os.path.join(out_dir, f"{outfile_prefix}.cml"),
component,
ConformerType.Model,
)
self.__write_molecule(
os.path.join(out_dir, f"{component.id}.cif"),
os.path.join(out_dir, f"{outfile_prefix}.cif"),
component,
ConformerType.AllConformers,
)
Expand Down

0 comments on commit ad52113

Please sign in to comment.