Coverage for biobb_flexdyn/flexdyn/concoord_disco.py: 69%
125 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 07:02 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 07:02 +0000
1#!/usr/bin/env python3
3"""Module containing the concoord_disco class and the command line interface."""
4from typing import Optional
5import os
6import shutil
7from pathlib import Path, PurePath
8from biobb_common.tools import file_utils as fu
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools.file_utils import launchlogger
13class ConcoordDisco(BiobbObject):
14 """
15 | biobb_flexdyn ConcoordDisco
16 | Wrapper of the Disco tool from the Concoord package.
17 | Structure generation based on a set of geometric constraints extracted with the Concoord Dist tool.
19 Args:
20 input_pdb_path (str): Input structure file in PDB format. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/data/flexdyn/structure.pdb>`_. Accepted formats: pdb (edam:format_1476).
21 input_dat_path (str): Input dat with structure interpretation and bond definitions. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/data/flexdyn/dist.dat>`_. Accepted formats: dat (edam:format_1637), txt (edam:format_2330).
22 output_traj_path (str): Output trajectory file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/disco_trj.pdb>`_. Accepted formats: pdb (edam:format_1476), xtc (edam:format_3875), gro (edam:format_2033).
23 output_rmsd_path (str): Output rmsd file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/disco_rmsd.dat>`_. Accepted formats: dat (edam:format_1637).
24 output_bfactor_path (str): Output B-factor file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/disco_bfactor.pdb>`_. Accepted formats: pdb (edam:format_1476).
25 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
26 * **binary_path** (*str*) - ("disco") Concoord disco binary path to be used.
27 * **vdw** (*int*) - (1) Select a set of Van der Waals parameters. Values: 1 (OPLS-UA -united atoms- parameters), 2 (OPLS-AA -all atoms- parameters), 3 (PROLSQ repel parameters), 4 (Yamber2 parameters), 5 (Li et al. parameters), 6 (OPLS-X parameters -recommended for NMR structure determination-)
28 * **concoord_lib_path** (*str*) - (None) Path to Concoord library files. If not specified will look for CONCOORDLIB conda environment variable.
29 * **num_structs** (*int*) - (500) Number of structures to be generated
30 * **num_iterations** (*int*) - (2500) Maximum number of iterations per structure
31 * **chirality_check** (*int*) - (2) Chirality check. Values: 0 (no chirality checks), 1 (only check afterwards), 2 (check on the fly)
32 * **bs** (*int*) - (0) Number of rounds of triangular bound smoothing (default 0), (if >= 6, tetragonal BS is activated)
33 * **nofit** (*bool*) - (False) Do not fit generated structures to reference
34 * **seed** (*int*) - (741265) Initial random seed
35 * **violation** (*float*) - (1.0) Maximal acceptable sum of violations (nm)
36 * **nofit** (*bool*) - (False) Do not fit generated structures to reference
37 * **convergence** (*int*) - (50) Consider convergence failed after this number of non-productive iterations
38 * **trials** (*int*) - (25) Maximum number of trials per run
39 * **damp** (*int*) - (1) Damping factor for distance corrections. Values: 1 (default), 2 (for cases with convergence problems)
40 * **dyn** (*int*) - (1) Number of rounds to dynamically set tolerances
41 * **bump** (*bool*) - (False) Do extra bump check
42 * **pairlist_freq** (*int*) - (10) Pairlist update frequency in steps (only valid together with bump)
43 * **cutoff** (*float*) - (0.5) Cut-off radius for pairlist (nm) (only valid together with bump)
44 * **ref** (*bool*) - (False) Use input coordinates instead of random starting coordinates
45 * **scale** (*int*) - (1) Pre-scale coordinates with this factor
46 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
47 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
48 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
49 * **container_path** (*str*) - (None) Path to the binary executable of your container.
50 * **container_image** (*str*) - ("cmip/cmip:latest") Container Image identifier.
51 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
52 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
53 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
54 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
56 Examples:
57 This is a use example of how to use the building block from Python::
59 from biobb_flexdyn.flexdyn.concoord_disco import concoord_disco
60 prop = {
61 'vdw' : 4,
62 'num_structs' : 20
63 }
64 concoord_disco( input_pdb_path='/path/to/dist_input.pdb',
65 input_dat_path='/path/to/dist_input.dat',
66 output_traj_path='/path/to/disco_out_traj.pdb',
67 output_rmsd_path='/path/to/disco_out_rmsd.dat',
68 output_bfactor_path='/path/to/disco_out_bfactor.pdb',
69 properties=prop)
71 Info:
72 * wrapped_software:
73 * name: Concoord
74 * version: >=2.1.2
75 * license: other
76 * ontology:
77 * name: EDAM
78 * schema: http://edamontology.org/EDAM.owl
80 """
82 def __init__(self, input_pdb_path: str, input_dat_path: str, output_traj_path: str,
83 output_rmsd_path: str, output_bfactor_path: str, properties: Optional[dict] = None, **kwargs) -> None:
85 properties = properties or {}
87 # Call parent class constructor
88 super().__init__(properties)
89 self.locals_var_dict = locals().copy()
91 # Input/Output files
92 self.io_dict = {
93 'in': {'input_pdb_path': input_pdb_path,
94 'input_dat_path': input_dat_path},
95 'out': {'output_traj_path': output_traj_path,
96 'output_rmsd_path': output_rmsd_path,
97 'output_bfactor_path': output_bfactor_path}
98 }
100 # Properties specific for BB
101 self.properties = properties
102 self.binary_path = properties.get('binary_path', 'disco')
104 self.vdw = properties.get('vdw')
105 self.concoord_lib_path = properties.get('concoord_lib_path', None)
106 self.num_structs = properties.get('num_structs')
107 self.num_iterations = properties.get('num_iterations')
108 self.chirality_check = properties.get('chirality_check')
109 self.bs = properties.get('bs')
110 self.nofit = properties.get('nofit')
111 self.seed = properties.get('seed')
112 self.violation = properties.get('violation')
113 self.convergence = properties.get('convergence')
114 self.trials = properties.get('trials')
115 self.damp = properties.get('damp')
116 self.dyn = properties.get('dyn')
117 self.bump = properties.get('bump')
118 self.pairlist_freq = properties.get('pairlist_freq')
119 self.cutoff = properties.get('cutoff')
120 self.ref = properties.get('ref')
121 self.scale = properties.get('scale')
123 # Check the properties
124 self.check_properties(properties)
125 self.check_arguments()
127 @launchlogger
128 def launch(self):
129 """Launches the execution of the FlexDyn ConcoordDisco module."""
131 # Setup Biobb
132 if self.check_restart():
133 return 0
134 self.stage_files()
136 # Copy auxiliary files (MARGINS, ATOMS, BONDS) according to the VdW property to the working dir
137 if self.concoord_lib_path is None:
138 concoord_lib = os.getenv("CONCOORDLIB")
139 else:
140 concoord_lib = self.concoord_lib_path
142 # MARGINS_li.DAT, MARGINS_oplsaa.DAT, MARGINS_oplsua.DAT, MARGINS_oplsx.DAT, MARGINS_repel.DAT, MARGINS_yamber2.DAT
143 # 1 (OPLS-UA -united atoms- parameters), 2 (OPLS-AA -all atoms- parameters), 3 (PROLSQ repel parameters), 4 (Yamber2 parameters), 5 (Li et al. parameters), 6 (OPLS-X parameters -recommended for NMR structure determination-).
144 vdw_values = ["vdw_values", "oplsua", "oplsaa", "repel", "yamber2", "li", "oplsx"]
145 if self.vdw is None:
146 raise ValueError("The 'vdw' property cannot be None")
147 vdw_index = int(self.vdw)
148 margins_file = str(concoord_lib) + "/MARGINS_" + vdw_values[vdw_index] + ".DAT"
149 atoms_file = str(concoord_lib) + "/ATOMS_" + vdw_values[vdw_index] + ".DAT"
150 bonds_file = str(concoord_lib) + "/BONDS.DAT"
151 shutil.copy2(margins_file, self.stage_io_dict.get("unique_dir", ""))
152 shutil.copy2(margins_file, self.stage_io_dict.get("unique_dir", "")+"/MARGINS.DAT")
153 shutil.copy2(atoms_file, self.stage_io_dict.get("unique_dir", ""))
154 shutil.copy2(bonds_file, self.stage_io_dict.get("unique_dir", ""))
156 # Determine working directory (host unique_dir or container volume path)
157 if self.container_path:
158 working_dir = self.container_volume_path if self.container_volume_path else "/data"
159 else:
160 working_dir = self.stage_io_dict.get('unique_dir', '')
162 # Command line
163 # (concoord) OROZCO67:biobb_flexdyn hospital$ disco -d biobb_flexdyn/test/reference/flexdyn/dist.dat
164 # -p biobb_flexdyn/test/reference/flexdyn/dist.pdb -op patata.pdb
165 self.cmd = ["cd", working_dir, ";", self.binary_path,
166 "-p", PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name,
167 "-d", PurePath(self.stage_io_dict["in"]["input_dat_path"]).name,
168 "-or", PurePath(self.stage_io_dict["out"]["output_rmsd_path"]).name,
169 "-of", PurePath(self.stage_io_dict["out"]["output_bfactor_path"]).name
170 ]
172 # Output structure formats:
173 file_extension = Path(self.stage_io_dict["out"]["output_traj_path"]).suffix
174 if file_extension == ".pdb":
175 self.cmd.append('-on') # NMR-PDB format (multi-model)
176 self.cmd.append(PurePath(self.stage_io_dict["out"]["output_traj_path"]).name)
177 elif file_extension == ".gro":
178 self.cmd.append('-ot')
179 self.cmd.append(PurePath(self.stage_io_dict["out"]["output_traj_path"]).name)
180 elif file_extension == ".xtc":
181 self.cmd.append('-ox')
182 self.cmd.append(PurePath(self.stage_io_dict["out"]["output_traj_path"]).name)
183 else:
184 fu.log("ERROR: output_traj_path ({}) must be a PDB, GRO or XTC formatted file ({})".format(self.io_dict["out"]["output_traj_path"], file_extension), self.out_log, self.global_log)
186 # Properties
187 if self.num_structs:
188 self.cmd.append('-n')
189 self.cmd.append(str(self.num_structs))
191 if self.num_iterations:
192 self.cmd.append('-i')
193 self.cmd.append(str(self.num_iterations))
195 if self.chirality_check:
196 self.cmd.append('-c')
197 self.cmd.append(str(self.chirality_check))
199 if self.bs:
200 self.cmd.append('-bs')
201 self.cmd.append(str(self.bs))
203 if self.cutoff:
204 self.cmd.append('-rc')
205 self.cmd.append(str(self.cutoff))
207 if self.seed:
208 self.cmd.append('-s')
209 self.cmd.append(str(self.seed))
211 if self.damp:
212 self.cmd.append('-damp')
213 self.cmd.append(str(self.damp))
215 if self.violation:
216 self.cmd.append('-viol')
217 self.cmd.append(str(self.violation))
219 if self.convergence:
220 self.cmd.append('-con')
221 self.cmd.append(str(self.convergence))
223 if self.trials:
224 self.cmd.append('-t')
225 self.cmd.append(str(self.trials))
227 if self.dyn:
228 self.cmd.append('-dyn')
229 self.cmd.append(str(self.dyn))
231 if self.pairlist_freq:
232 self.cmd.append('-l')
233 self.cmd.append(str(self.pairlist_freq))
235 if self.scale:
236 self.cmd.append('-is')
237 self.cmd.append(str(self.scale))
239 if self.nofit:
240 self.cmd.append('-f')
242 if self.bump:
243 self.cmd.append('-bump')
245 if self.ref:
246 self.cmd.append('-ref')
248 # Run Biobb block
249 self.run_biobb()
251 # Copy files to host
252 self.copy_to_host()
254 # remove temporary folder(s)
255 self.remove_tmp_files()
257 self.check_arguments(output_files_created=True, raise_exception=False)
259 return self.return_code
262def concoord_disco(input_pdb_path: str, input_dat_path: str,
263 output_traj_path: str, output_rmsd_path: str, output_bfactor_path: str,
264 properties: Optional[dict] = None, **kwargs) -> int:
265 """Create :class:`ConcoordDisco <flexdyn.concoord_disco.ConcoordDisco>`flexdyn.concoord_disco.ConcoordDisco class and
266 execute :meth:`launch() <flexdyn.concoord_disco.ConcoordDisco.launch>` method"""
267 return ConcoordDisco(**dict(locals())).launch()
270concoord_disco.__doc__ = ConcoordDisco.__doc__
271main = ConcoordDisco.get_main(concoord_disco, "Structure generation based on a set of geometric constraints extracted with the Concoord Dist tool.")
273if __name__ == '__main__':
274 main()