#!/usr/bin/env python3
"""Module containing the nma_run class and the command line interface."""
from typing import Optional
import os
from pathlib import PurePath
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.tools.file_utils import launchlogger
[docs]
class NMARun(BiobbObject):
"""
| biobb_flexserv NMARun
| Wrapper of the Normal Mode Analysis tool from the FlexServ module.
| Generates protein conformational structures using the Normal Mode Analysis (NMA) method.
Args:
input_pdb_path (str): Input PDB file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/data/flexserv/structure.ca.pdb>`_. Accepted formats: pdb (edam:format_1476).
output_log_path (str): Output log file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/flexserv/nma_run_out.log>`_. Accepted formats: log (edam:format_2330), out (edam:format_2330), txt (edam:format_2330), o (edam:format_2330).
output_crd_path (str): Output ensemble. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/flexserv/nma_run_out.crd>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878).
properties (dict - Python dictionary object containing the tool parameters, not input/output files):
* **binary_path** (*str*) - ("diaghess") NMA binary path to be used.
* **frames** (*int*) - (1000) Number of frames in the final ensemble
* **nvecs** (*int*) - (50) Number of vectors to take into account for the ensemble generation
* **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
* **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
* **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
* **container_path** (*str*) - (None) Container path definition.
* **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
* **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
* **container_working_dir** (*str*) - (None) Container working directory definition.
* **container_user_id** (*str*) - (None) Container user_id definition.
* **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
Examples:
This is a use example of how to use the building block from Python::
from biobb_flexserv.flexserv.bd_run import bd_run
prop = {
'binary_path': 'diaghess'
}
flexserv_run(input_pdb_path='/path/to/nma_input.pdb',
output_log_path='/path/to/nma_log.log',
output_crd_path='/path/to/nma_ensemble.crd',
properties=prop)
Info:
* wrapped_software:
* name: FlexServ Normal Mode Analysis
* version: >=1.0
* license: Apache-2.0
* ontology:
* name: EDAM
* schema: http://edamontology.org/EDAM.owl
"""
def __init__(self, input_pdb_path: str, output_log_path: str,
output_crd_path: str, properties: Optional[dict] = None, **kwargs) -> None:
properties = properties or {}
# Call parent class constructor
super().__init__(properties)
self.locals_var_dict = locals().copy()
# Input/Output files
self.io_dict = {
'in': {'input_pdb_path': input_pdb_path},
'out': {'output_log_path': output_log_path,
'output_crd_path': output_crd_path}
}
# Properties specific for BB
self.properties = properties
self.binary_path = properties.get('binary_path', 'diaghess')
self.frames = properties.get('frames', 1000)
self.nvecs = properties.get('nvecs', 50)
# Check the properties
self.check_properties(properties)
self.check_arguments()
[docs]
@launchlogger
def launch(self):
"""Launches the execution of the FlexServ NMARun module."""
# Setup Biobb
if self.check_restart():
return 0
self.stage_files()
if self.container_path:
working_dir = self.container_volume_path if self.container_volume_path else "/data"
else:
working_dir = self.stage_io_dict.get("unique_dir", "")
input_pdb = PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name
output_crd = PurePath(self.stage_io_dict["out"]["output_crd_path"]).name
output_log = PurePath(self.stage_io_dict["out"]["output_log_path"]).name
# Command line
# nmanu.pl structure.ca.pdb hessian.dat 1 0 40
# diaghess
# mc-eigen.pl eigenvec.dat > file.proj
# pca_anim_mc.pl -pdb structure.ca.pdb -evec eigenvec.dat -i file.proj -n 50 -pout traj.crd
if self.container_path:
conda_path = "/usr/local"
else:
conda_path = os.getenv("CONDA_PREFIX")
nmanu = str(conda_path) + "/bin/nmanu.pl"
nma_eigen = str(conda_path) + "/bin/mc-eigen-mdweb.pl"
pca_anim = str(conda_path) + "/bin/pca_anim_mc.pl"
self.cmd = ["cd", working_dir, ";",
"perl",
nmanu,
input_pdb,
"hessian.dat", "1", "0", "40", ";",
self.binary_path,
";", "perl",
nma_eigen, "eigenvec.dat", str(self.frames), ">", "file.proj",
";", "perl",
pca_anim,
"-pdb",
input_pdb,
"-evec", "eigenvec.dat", "-i", "file.proj", "-n", str(self.nvecs),
"-pout", output_crd,
'>', output_log
]
# Run Biobb block
self.run_biobb()
# Copy files to host
self.copy_to_host()
# Remove temporary folder(s)
self.remove_tmp_files()
self.check_arguments(output_files_created=True, raise_exception=False)
return self.return_code
[docs]
def nma_run(input_pdb_path: str,
output_log_path: str, output_crd_path: str,
properties: Optional[dict] = None, **kwargs) -> int:
"""Create :class:`NMARun <flexserv.nma_run.NMARun>`flexserv.nma_run.NMARun class and
execute :meth:`launch() <flexserv.nma_run.NMARun.launch>` method"""
return NMARun(**dict(locals())).launch()
nma_run.__doc__ = NMARun.__doc__
main = NMARun.get_main(nma_run, "Generates protein conformational structures using the Normal Mode Analysis method.")
if __name__ == '__main__':
main()