From c1106a1a2aa90cea301d065dc6259a0b4408fd63 Mon Sep 17 00:00:00 2001 From: dennisbrookner Date: Mon, 3 Jun 2024 17:03:42 -0400 Subject: [PATCH 1/5] begin refactoring args into dictionaries, like in careless --- src/matchmaps/_args.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/matchmaps/_args.py diff --git a/src/matchmaps/_args.py b/src/matchmaps/_args.py new file mode 100644 index 0000000..9d25a7e --- /dev/null +++ b/src/matchmaps/_args.py @@ -0,0 +1,51 @@ +""" +Dictionaries for arguments parsed by one or more matchmaps utilities +""" + +matchmaps_description = ( + "Compute a real-space difference map. " + "You will need two MTZ files, which will be referred to throughout as 'on' and 'off', " + "though they could also be light/dark, bound/apo, mutant/WT, hot/cold, etc. " + "Each mtz will need to contain structure factor amplitudes and uncertainties; you will not need any phases. " + "You will, however, need an input model (assumed to correspond with the 'off' state) which will be used to determine phases. " + "The input file may be in .pdb or .cif format. " + "Please note that both ccp4 and phenix must be installed and active in your environment for this function to run. " + "" + "More information can be found online at https://rs-station.github.io/matchmaps/index.html" + ) + +matchmaps_mr_description = () + +matchmaps_ncs_description = () + +common_args = ( + # args used by all three utilities + (("--ligands", "-l"), { + "help":"Any .cif restraint files needed for refinement", + "required": False, + "default": None, + "nargs": "*", + }), + + (("--output-dir", "-o"), { + "help": "Any .cif restraint files needed for refinement", + "required": False, + "default": None, + "nargs": "*", + }), + + (("reflection_files", ), { + "metavar":"reflections.{mtz,stream}", + "help":"Mtz or stream file(s) containing unmerged reflection observations. " + "If you are supplying stream files, you must also use the --spacegroups option to supply the symmetry for merging. " + "See the metadata_keys param for more info about stream file usage.", + "type":str, + "nargs":'+', + }), + + (("output_base", ), { + "metavar":"out", + "help":"Output filename base.", + "type":str, + }), +) \ No newline at end of file From 169647106c13ae9cb81b4d949604509a3b9bf77f Mon Sep 17 00:00:00 2001 From: dennisbrookner Date: Mon, 3 Jun 2024 17:16:15 -0400 Subject: [PATCH 2/5] continue refactoring args --- src/matchmaps/_args.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/matchmaps/_args.py b/src/matchmaps/_args.py index 9d25a7e..3a40dce 100644 --- a/src/matchmaps/_args.py +++ b/src/matchmaps/_args.py @@ -27,25 +27,16 @@ "nargs": "*", }), - (("--output-dir", "-o"), { - "help": "Any .cif restraint files needed for refinement", + (("--input-dir", "-i"), { + "help": "Path to input files. Optional, defaults to './' (current directory)", "required": False, - "default": None, - "nargs": "*", + "default": "./", }), - (("reflection_files", ), { - "metavar":"reflections.{mtz,stream}", - "help":"Mtz or stream file(s) containing unmerged reflection observations. " - "If you are supplying stream files, you must also use the --spacegroups option to supply the symmetry for merging. " - "See the metadata_keys param for more info about stream file usage.", - "type":str, - "nargs":'+', + (("--output-dir", "-o"), { + "help": "Path to which output files should be written. Optional, defaults to './' (current directory)", + "required": False, + "default": "./", }), - (("output_base", ), { - "metavar":"out", - "help":"Output filename base.", - "type":str, - }), ) \ No newline at end of file From b70a38f32e35b744ddf9d3cc97924ee313116ec6 Mon Sep 17 00:00:00 2001 From: dennisbrookner Date: Tue, 18 Jun 2024 12:06:14 -0400 Subject: [PATCH 3/5] refactored args --- src/matchmaps/_args.py | 210 +++++++++++++++++++++++++++++++++++++- src/matchmaps/_parsers.py | 27 +++++ 2 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 src/matchmaps/_parsers.py diff --git a/src/matchmaps/_args.py b/src/matchmaps/_args.py index 3a40dce..7f9800d 100644 --- a/src/matchmaps/_args.py +++ b/src/matchmaps/_args.py @@ -14,14 +14,148 @@ "More information can be found online at https://rs-station.github.io/matchmaps/index.html" ) -matchmaps_mr_description = () +matchmaps_mr_description = ( + "Compute a real-space difference map between inputs in different space groups / crystal packings. " + "You will need two MTZ files, which will be referred to throughout as 'on' and 'off', " + "though they could also be light/dark, bound/apo, mutant/WT, hot/cold, etc. " + "Each mtz will need to contain structure factor amplitudes and uncertainties; you will not need any phases. " + "You will, however, need an input model (assumed to correspond with the 'off' state) which will be used to determine phases. " + "The input file may be in .pdb or .cif format. " + "Please note that phenix must be installed and active in your environment for this function to run. " + "" + "If your mtzoff and mtzon are in the same spacegroup and crystal packing, see the basic matchmaps utility. " + "More information can be found online at https://rs-station.github.io/matchmaps/index.html" + ) -matchmaps_ncs_description = () +matchmaps_ncs_description = ( + "Compute an 'internal' real-space difference map between NCS-related molecules. " + "You will need an MTZ file with structure factor amplitudes and optionally containing phases, and a PDB/CIF file." + "" + "Please note that phenix must be installed and active in your environment for this function to run. " + "" + "More information can be found online at https://rs-station.github.io/matchmaps/index.html" + ) + +base_and_mr_args = ( + (("--mtzoff", "-f"), { + "nargs": 3, + "metavar": ("mtzfileoff", "Foff", "SigFoff"), + "required": True, + "help": ( + "MTZ or sfCIF containing off/apo/ground/dark state data. " + "Specified as [filename F SigF]" + ), + }), + + (("--mtzon", "-n"), { + "nargs": 3, + "metavar": ("mtzfileon", "Fon", "SigFon"), + "required": True, + "help": ( + "MTZ or sfCIF containing on/bound/excited/bright state data. " + "Specified as [filename F SigF]" + ), + }), + + (("--pdboff", "-p"), { + "required": True, + "help": ( + "Reference PDB or mmCIF corresponding to the off/apo/ground/dark state. " + "Used for rigid-body refinement of both input MTZs to generate phases." + ), + }), + ("--on-as-stationary", { + "required": False, + "action": "store_true", + "default": False, + "help": ( + "Include this flag to align 'off' data onto 'on' data. By default, 'off' data is stationary and 'on' data is moved." + ), + }), + + ("--alpha", { + "required": False, + "type": float, + "default": 0, + "help": ( + "Alpha to use for error weighting of F-obs prior to Fourier Transform. " + "Weights are computed as: 1 / ((1+(alpha*(SigF^2)) / ^2). " + "Default value is alpha=0, e.g., no weighting is performed. " + ) + }), + + ("--unmasked-radius", { + "required": False, + "type": float, + "default": 5, + "help": ( + "Maximum distance (in Anstroms) away from protein model to include voxels. Only applies to the 'unmasked' difference map output. " + "Defaults to 5. " + "Note that the regular difference map (e.g. the 'masked' version) is not affected by this parameter and maintains a solvent mask radius of 2 Angstroms." + ), + }), + + (("--rbr-selections", "-r"), { + "required": False, + "default": None, + "nargs": "*", + "help": ( + "Specification of multiple rigid-body groups for refinement. By default, everything is refined as one rigid-body group. " + ), + }), +) + +ncs_args = ( + (("--mtz", "-m"), { + "nargs": "*", + "required": True, + "help": ( + "MTZ or sfCIF file containing structure factor amplitudes. " + "Specified as [filename F SigF] or [filename F]. " + "SigF is not necessary if phases are also provided" + ), + }), + + ("--phases", { + "required": False, + "default": None, + "help": ( + "Optional. Column in MTZ/sfCIF file containing phases. " + "If phases are not provided, phases will be computed via rigid-body refinement of " + "the provided model and structure factor amplitudes." + ), + }), + + (("--pdb", "-p"), { + "required": True, + "help": ( + "Reference PDB or mmCIF. " + "If phases are not provided, used for rigid-body refinement of input MTZ/sfCIF to generate phases." + ), + }), + + (("--ncs-chains", "-n"), { + "required": True, + "metavar": ("fixed_chain", "moving_chain"), + "default": None, + "nargs": 2, + "help": ( + "NCS chains to overlay and subtract, specified as [fixed_chain, moving_chain]." + "E.g. to overlay chain C onto chain B, specify: --ncs-chains B C" + ), + }), + + ("--mapname", { + "required": False, + "default": "matchmaps_ncs", + "help": "Base filename for the output map files. " + }) +) common_args = ( # args used by all three utilities - (("--ligands", "-l"), { - "help":"Any .cif restraint files needed for refinement", + (("--ligands", "-l"), { + "help": "Any .cif restraint files needed for refinement", "required": False, "default": None, "nargs": "*", @@ -39,4 +173,72 @@ "default": "./", }), + (("--spacing", "-s"), { + "help": ( + "Approximate voxel size in Angstroms for real-space maps. Defaults to 0.5 A. " + "Value is approximate because there must be an integer number of voxels along each unit cell dimension" + ), + "required": False, + "default": 0.5, + "type": float, + }), + + ("--dmin", { + "help": ( + "Highest-resolution (in Angstroms) reflections to include in Fourier transform for FloatGrid creation. " + "By default, cutoff is the resolution limit of the lower-resolution input MTZ. " + ), + "required": False, + "type": float, + "default": None, + }), + + ("--no-bss", { + "help": ( + "Include this flag to skip bulk solvent scaling in phenix.refine. By default, BSS is included." + ), + "required": False, + "action": "store_true", + "default": False, + }), + + (("--verbose", "-v"), { + "help": "Include this flag to print out scaleit and phenix.refine outputs to the terminal. Useful for troubleshooting, but annoying; defaults to False.", + "required": False, + "action": "store_true", + "default": False, + }), + + ("--eff", { + "help": "Custom .eff template for running phenix.refine. ", + "required": False, + "default": None, + }), + + (("--keep-temp-files", "-k"), { + "required": False, + "default": None, + "help": ( + "Do not delete intermediate matchmaps files, but rather place them in the supplied directory. " + "This directory is created as a subdirectory of the supplied output-dir." + )}), + + ("--script", { + "required": False, + "default": "run_matchmaps", + "help": ( + "Name for a file {script}.sh which can be run to repeat this command. " + "By default, this file is called `run_matchmaps.sh`. " + "Note that this file is written out in the current working directory, NOT the input or output directories" + ) + }), + + ("--phenix-version", { + "required": False, + "help": ( + "Specify phenix version as a string, e.g. '1.20'. " + "If omitted, matchmaps will attempt to automatically detect the version in use " + "by analyzing the output of phenix.version" + ) + }), ) \ No newline at end of file diff --git a/src/matchmaps/_parsers.py b/src/matchmaps/_parsers.py new file mode 100644 index 0000000..1bb50b9 --- /dev/null +++ b/src/matchmaps/_parsers.py @@ -0,0 +1,27 @@ +import argparse + +from matchmaps._args import ( + matchmaps_description, + matchmaps_mr_description, + matchmaps_ncs_description, + base_and_mr_args, + ncs_args, + common_args +) + +matchmaps_parser = argparse.ArgumentParser(description=matchmaps_description) +matchmaps_mr_parser = argparse.ArgumentParser(description=matchmaps_mr_description) +matchmaps_ncs_parser = argparse.ArgumentParser(description=matchmaps_ncs_description) + +for args, kwargs in base_and_mr_args: + matchmaps_parser.add_argument(*args, **kwargs) + matchmaps_mr_parser.add_argument(*args, **kwargs) + +for args, kwargs in ncs_args: + matchmaps_ncs_parser.add_argument(*args, **kwargs) + +for args, kwargs in common_args: + matchmaps_parser.add_argument(*args, **kwargs) + matchmaps_mr_parser.add_argument(*args, **kwargs) + matchmaps_ncs_parser.add_argument(*args, **kwargs) + From 9a83f276b71fa1e3fe753ed8f7b05be4cf2e410f Mon Sep 17 00:00:00 2001 From: dennisbrookner Date: Tue, 18 Jun 2024 12:17:55 -0400 Subject: [PATCH 4/5] import parsers into scripts --- src/matchmaps/_args.py | 20 +- src/matchmaps/_compute_mr_diff.py | 214 +------------------ src/matchmaps/_compute_ncs_diff.py | 180 +--------------- src/matchmaps/_compute_realspace_diff.py | 250 +++-------------------- 4 files changed, 37 insertions(+), 627 deletions(-) diff --git a/src/matchmaps/_args.py b/src/matchmaps/_args.py index 7f9800d..aa5502f 100644 --- a/src/matchmaps/_args.py +++ b/src/matchmaps/_args.py @@ -64,7 +64,7 @@ "Used for rigid-body refinement of both input MTZs to generate phases." ), }), - ("--on-as-stationary", { + (("--on-as-stationary",), { "required": False, "action": "store_true", "default": False, @@ -73,7 +73,7 @@ ), }), - ("--alpha", { + (("--alpha",), { "required": False, "type": float, "default": 0, @@ -84,7 +84,7 @@ ) }), - ("--unmasked-radius", { + (("--unmasked-radius",), { "required": False, "type": float, "default": 5, @@ -116,7 +116,7 @@ ), }), - ("--phases", { + (("--phases",), { "required": False, "default": None, "help": ( @@ -145,7 +145,7 @@ ), }), - ("--mapname", { + (("--mapname",), { "required": False, "default": "matchmaps_ncs", "help": "Base filename for the output map files. " @@ -183,7 +183,7 @@ "type": float, }), - ("--dmin", { + (("--dmin",), { "help": ( "Highest-resolution (in Angstroms) reflections to include in Fourier transform for FloatGrid creation. " "By default, cutoff is the resolution limit of the lower-resolution input MTZ. " @@ -193,7 +193,7 @@ "default": None, }), - ("--no-bss", { + (("--no-bss",), { "help": ( "Include this flag to skip bulk solvent scaling in phenix.refine. By default, BSS is included." ), @@ -209,7 +209,7 @@ "default": False, }), - ("--eff", { + (("--eff",), { "help": "Custom .eff template for running phenix.refine. ", "required": False, "default": None, @@ -223,7 +223,7 @@ "This directory is created as a subdirectory of the supplied output-dir." )}), - ("--script", { + (("--script",), { "required": False, "default": "run_matchmaps", "help": ( @@ -233,7 +233,7 @@ ) }), - ("--phenix-version", { + (("--phenix-version",), { "required": False, "help": ( "Specify phenix version as a string, e.g. '1.20'. " diff --git a/src/matchmaps/_compute_mr_diff.py b/src/matchmaps/_compute_mr_diff.py index 6d13724..0705a94 100644 --- a/src/matchmaps/_compute_mr_diff.py +++ b/src/matchmaps/_compute_mr_diff.py @@ -9,6 +9,7 @@ import gemmi import reciprocalspaceship as rs +from matchmaps._parsers import matchmaps_mr_parser from matchmaps._phenix_utils import rigid_body_refinement_wrapper, phaser_wrapper, _remove_waters from matchmaps._utils import ( _handle_special_positions, @@ -241,219 +242,8 @@ def compute_mr_difference_map( return -def parse_arguments(): - """Parse commandline arguments.""" - parser = argparse.ArgumentParser( - description=( - "Compute a real-space difference map between inputs in different space groups / crystal packings. " - "You will need two MTZ files, which will be referred to throughout as 'on' and 'off', " - "though they could also be light/dark, bound/apo, mutant/WT, hot/cold, etc. " - "Each mtz will need to contain structure factor amplitudes and uncertainties; you will not need any phases. " - "You will, however, need an input model (assumed to correspond with the 'off' state) which will be used to determine phases. " - "The input file may be in .pdb or .cif format. " - "Please note that phenix must be installed and active in your environment for this function to run. " - "" - "If your mtzoff and mtzon are in the same spacegroup and crystal packing, see the basic matchmaps utility. " - "More information can be found online at https://rs-station.github.io/matchmaps/index.html" - ) - ) - - parser.add_argument( - "--mtzoff", - "-f", - nargs=3, - metavar=("mtzfileoff", "Foff", "SigFoff"), - required=True, - help=( - "MTZ or sfCIF containing off/apo/ground/dark state data. " - "Specified as [filename F SigF]" - ), - ) - - parser.add_argument( - "--mtzon", - "-n", - nargs=3, - metavar=("mtzfileon", "Fon", "SigFon"), - required=True, - help=( - "MTZ or SFCIF containing on/bound/excited/bright state data. " - "Specified as [filename F SigF]" - "This file may be in a different spacegroup / crystal packing than mtzoff" - ), - ) - - parser.add_argument( - "--pdboff", - "-p", - required=True, - help=( - "Reference PDB or mmCIF corresponding to the off/apo/ground/dark state. " - "Used as a molecular replacement solution for mtzon and for rigid-body refinement of both input MTZs to generate phases." - "Should match mtzoff well enough that molecular replacement is not necessary." - ), - ) - - parser.add_argument( - "--ligands", - "-l", - required=False, - default=None, - nargs="*", - help=("Any .cif restraint files needed for refinement"), - ) - - parser.add_argument( - "--input-dir", - "-i", - required=False, - default="./", - help="Path to input files. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--output-dir", - "-o", - required=False, - default="./", - help="Path to which output files should be written. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--on-as-stationary", - required=False, - action="store_true", - default=False, - help=( - "Include this flag to align 'off' data onto 'on' data. By default, 'off' data is stationary and 'on' data is moved." - "For matchmaps.mr, this only applies to the post-molecular-replacement alignment; " - "all maps will be placed in the spacegroup of mtzoff." - ), - ) - - parser.add_argument( - "--no-bss", - required=False, - action="store_true", - default=False, - help=( - "Include this flag to skip bulk solvent scaling in phenix.refine. By default, BSS is included." - ), - ) - - parser.add_argument( - "--spacing", - "-s", - required=False, - type=float, - default=0.5, - help=( - "Approximate voxel size in Angstroms for real-space maps. Defaults to 0.5 A. " - "Value is approximate because there must be an integer number of voxels along each unit cell dimension" - ), - ) - - parser.add_argument( - "--dmin", - required=False, - type=float, - default=None, - help=( - "Highest-resolution (in Angstroms) reflections to include in Fourier transform for FloatGrid creation. " - "By default, cutoff is the resolution limit of the lower-resolution input MTZ. " - ), - ) - - parser.add_argument( - "--unmasked-radius", - required=False, - type=float, - default=5, - help=( - "Maximum distance (in Anstroms) away from protein model to include voxels. Only applies to the 'unmasked' difference map output. " - "Defaults to 5. " - "Note that the regular difference map (e.g. the 'masked' version) is not affected by this parameter and maintains a solvent mask radius of 2 Angstroms." - ), - ) - - parser.add_argument( - "--alpha", - required=False, - type=float, - default=0, - help=( - "Alpha to use for error weighting of F-obs prior to Fourier Transform. " - "Weights are computed as: 1 / ((1+(alpha*(SigF^2)) / ^2). " - "Default value is alpha=0, e.g., no weighting is performed. " - ) - ) - - parser.add_argument( - "--verbose", - "-v", - required=False, - action="store_true", - default=False, - help="Include this flag to print out phenix.phaser and phenix.refine outputs to the terminal. Useful for troubleshooting, but annoying; defaults to False.", - ) - - parser.add_argument( - "--rbr-selections", - "-r", - required=False, - default=None, - nargs="*", - help=( - "Specification of multiple rigid-body groups for refinement. By default, everything is refined as one rigid-body group. " - "For matchmaps.mr, everything will always be molecular replaced as a single rigid-body, but may then be refined as multiple rigid bodies." - ), - ) - - parser.add_argument( - "--eff", - required=False, - default=None, - help=("Custom .eff template for running phenix.refine. "), - ) - - parser.add_argument( - "--keep-temp-files", - "-k", - required=False, - default=None, - help=( - "Do not delete intermediate matchmaps files, but rather place them in the supplied directory. " - "This directory is created as a subdirectory of the supplied output-dir." - ) - ) - - parser.add_argument( - "--script", - required=False, - default='run_matchmaps', - help=( - "Name for a file {script}.sh which can be run to repeat this command. " - "By default, this file is called `run_matchmaps.sh`. " - "Note that this file is written out in the current working directory, NOT the input or output directories" - ) - ) - - parser.add_argument( - "--phenix-version", - required=False, - help=( - "Specify phenix version as a string, e.g. '1.20'. " - "If omitted, matchmaps will attempt to automatically detect the version in use " - "by analyzing the output of phenix.version" - ) - ) - - return parser - - def main(): - parser = parse_arguments() - args = parser.parse_args() + args = matchmaps_mr_parser.parse_args() if not os.path.exists(args.output_dir): os.makedirs(args.output_dir) diff --git a/src/matchmaps/_compute_ncs_diff.py b/src/matchmaps/_compute_ncs_diff.py index 15c6ad1..901a7d6 100644 --- a/src/matchmaps/_compute_ncs_diff.py +++ b/src/matchmaps/_compute_ncs_diff.py @@ -9,6 +9,7 @@ import gemmi import reciprocalspaceship as rs +from matchmaps._parsers import matchmaps_ncs_parser from matchmaps._phenix_utils import rigid_body_refinement_wrapper, _renumber_waters from matchmaps._utils import ( _handle_special_positions, @@ -166,185 +167,8 @@ def compute_ncs_difference_map( return -def parse_arguments(): - """Parse commandline arguments.""" - parser = argparse.ArgumentParser( - description=( - "Compute an 'internal' real-space difference map between NCS-related molecules. " - "You will need an MTZ file with structure factor amplitudes and optionally containing phases, and a PDB/CIF file." - "" - "Please note that phenix must be installed and active in your environment for this function to run. " - "" - "More information can be found online at https://rs-station.github.io/matchmaps/index.html" - ) - ) - - parser.add_argument( - "--mtz", - "-m", - nargs="*", - # metavar=("mtzfile", "F", "SigF"), - required=True, - help=( - "MTZ or sfCIF file containing structure factor amplitudes. " - "Specified as [filename F SigF] or [filename F]. " - "SigF is not necessary if phases are also provided" - ), - ) - - parser.add_argument( - "--phases", - required=False, - default=None, - help=( - "Optional. Column in MTZ/sfCIF file containing phases. " - "If phases are not provided, phases will be computed via rigid-body refinement of " - "the provided model and structure factor amplitudes." - ), - ) - - parser.add_argument( - "--pdb", - "-p", - required=True, - help=( - "Reference PDB or mmCIF. " - "If phases are not provided, used for rigid-body refinement of input MTZ/sfCIF to generate phases." - ), - ) - - parser.add_argument( - "--ncs-chains", - "-n", - required=True, - metavar=("fixed_chain", "moving_chain"), - default=None, - nargs=2, - help=( - "NCS chains to overlay and subtract, specified as [fixed_chain, moving_chain]." - "E.g. to overlay chain C onto chain B, specify: --ncs-chains B C" - ), - ) - - parser.add_argument( - "--mapname", - required=False, - default="matchmaps_ncs", - help=("Base filename for the output map files. "), - ) - - parser.add_argument( - "--ligands", - "-l", - required=False, - default=None, - nargs="*", - help=("Any .cif restraint files needed for refinement"), - ) - - parser.add_argument( - "--input-dir", - "-i", - required=False, - default="./", - help="Path to input files. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--output-dir", - "-o", - required=False, - default="./", - help="Path to which output files should be written. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--no-bss", - required=False, - action="store_true", - default=False, - help=( - "Include this flag to skip bulk solvent scaling in phenix.refine. By default, BSS is included." - ), - ) - - parser.add_argument( - "--spacing", - "-s", - required=False, - type=float, - default=0.5, - help=( - "Approximate voxel size in Angstroms for real-space maps. Defaults to 0.5 A. " - "Value is approximate because there must be an integer number of voxels along each unit cell dimension" - ), - ) - - parser.add_argument( - "--dmin", - required=False, - type=float, - default=None, - help=( - "Highest-resolution (in Angstroms) reflections to include in Fourier transform for FloatGrid creation. " - "By default, cutoff is the resolution limit of the input MTZ. " - ), - ) - - parser.add_argument( - "--verbose", - "-v", - required=False, - action="store_true", - default=False, - help="Include this flag to print out phenix.refine outputs to the terminal. Useful for troubleshooting, but annoying; defaults to False.", - ) - - parser.add_argument( - "--eff", - required=False, - default=None, - help=("Custom .eff template for running phenix.refine. "), - ) - - parser.add_argument( - "--keep-temp-files", - "-k", - required=False, - default=None, - help=( - "Do not delete intermediate matchmaps files, but rather place them in the supplied directory. " - "This directory is created as a subdirectory of the supplied output-dir." - ) - ) - - parser.add_argument( - "--script", - required=False, - default='run_matchmaps', - help=( - "Name for a file {script}.sh which can be run to repeat this command. " - "By default, this file is called `run_matchmaps.sh`. " - "Note that this file is written out in the current working directory, NOT the input or output directories" - ) - ) - - parser.add_argument( - "--phenix-version", - required=False, - help=( - "Specify phenix version as a string, e.g. '1.20'. " - "If omitted, matchmaps will attempt to automatically detect the version in use " - "by analyzing the output of phenix.version" - ) - ) - - return parser - - def main(): - parser = parse_arguments() - args = parser.parse_args() + args = matchmaps_ncs_parser.parse_args() (input_dir, output_dir, ligands, mtz, pdb) = _validate_inputs( args.input_dir, diff --git a/src/matchmaps/_compute_realspace_diff.py b/src/matchmaps/_compute_realspace_diff.py index 580bd55..0bb8219 100755 --- a/src/matchmaps/_compute_realspace_diff.py +++ b/src/matchmaps/_compute_realspace_diff.py @@ -9,6 +9,7 @@ import gemmi import reciprocalspaceship as rs +from matchmaps._parsers import matchmaps_parser from matchmaps._phenix_utils import rigid_body_refinement_wrapper, _renumber_waters from matchmaps._utils import ( _handle_special_positions, @@ -25,27 +26,27 @@ def compute_realspace_difference_map( - pdboff : Path, - mtzoff : Path, - mtzon : Path, - Foff : str, - SigFoff : str, - Fon : str, - SigFon : str, - ligands : list = None, - dmin : int = None, - spacing = 0.5, - on_as_stationary : bool = False, - input_dir=Path("."), - output_dir=Path("."), - verbose=False, - rbr_selections : list[str] = None, - eff : str = None, - keep_temp_files : str = None, - radius : float = 5, - alpha : float = 0, - no_bss = False, - phenix_version: str = None, + pdboff: Path, + mtzoff: Path, + mtzon: Path, + Foff: str, + SigFoff: str, + Fon: str, + SigFon: str, + ligands: list = None, + dmin: int = None, + spacing=0.5, + on_as_stationary: bool = False, + input_dir=Path("."), + output_dir=Path("."), + verbose=False, + rbr_selections: list[str] = None, + eff: str = None, + keep_temp_files: str = None, + radius: float = 5, + alpha: float = 0, + no_bss=False, + phenix_version: str = None, ): """ Compute a real-space difference map from mtzs. @@ -259,213 +260,8 @@ def compute_realspace_difference_map( return -def parse_arguments(): - """Parse commandline arguments.""" - parser = argparse.ArgumentParser( - description=( - "Compute a real-space difference map. " - "You will need two MTZ files, which will be referred to throughout as 'on' and 'off', " - "though they could also be light/dark, bound/apo, mutant/WT, hot/cold, etc. " - "Each mtz will need to contain structure factor amplitudes and uncertainties; you will not need any phases. " - "You will, however, need an input model (assumed to correspond with the 'off' state) which will be used to determine phases. " - "The input file may be in .pdb or .cif format. " - "Please note that both ccp4 and phenix must be installed and active in your environment for this function to run. " - "" - "More information can be found online at https://rs-station.github.io/matchmaps/index.html" - ) - ) - - parser.add_argument( - "--mtzoff", - "-f", - nargs=3, - metavar=("mtzfileoff", "Foff", "SigFoff"), - required=True, - help=( - "MTZ or sfCIF containing off/apo/ground/dark state data. " - "Specified as [filename F SigF]" - ), - ) - - parser.add_argument( - "--mtzon", - "-n", - nargs=3, - metavar=("mtzfileon", "Fon", "SigFon"), - required=True, - help=( - "MTZ or sfCIF containing on/bound/excited/bright state data. " - "Specified as [filename F SigF]" - ), - ) - - parser.add_argument( - "--pdboff", - "-p", - required=True, - help=( - "Reference PDB or mmCIF corresponding to the off/apo/ground/dark state. " - "Used for rigid-body refinement of both input MTZs to generate phases." - ), - ) - - parser.add_argument( - "--ligands", - "-l", - required=False, - default=None, - nargs="*", - help=("Any .cif restraint files needed for refinement"), - ) - - parser.add_argument( - "--input-dir", - "-i", - required=False, - default="./", - help="Path to input files. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--output-dir", - "-o", - required=False, - default="./", - help="Path to which output files should be written. Optional, defaults to './' (current directory)", - ) - - parser.add_argument( - "--on-as-stationary", - required=False, - action="store_true", - default=False, - help=( - "Include this flag to align 'off' data onto 'on' data. By default, 'off' data is stationary and 'on' data is moved." - ), - ) - - parser.add_argument( - "--no-bss", - required=False, - action="store_true", - default=False, - help=( - "Include this flag to skip bulk solvent scaling in phenix.refine. By default, BSS is included." - ), - ) - - parser.add_argument( - "--spacing", - "-s", - required=False, - type=float, - default=0.5, - help=( - "Approximate voxel size in Angstroms for real-space maps. Defaults to 0.5 A. " - "Value is approximate because there must be an integer number of voxels along each unit cell dimension" - ), - ) - - parser.add_argument( - "--dmin", - required=False, - type=float, - default=None, - help=( - "Highest-resolution (in Angstroms) reflections to include in Fourier transform for FloatGrid creation. " - "By default, cutoff is the resolution limit of the lower-resolution input MTZ. " - ), - ) - - parser.add_argument( - "--alpha", - required=False, - type=float, - default=0, - help=( - "Alpha to use for error weighting of F-obs prior to Fourier Transform. " - "Weights are computed as: 1 / ((1+(alpha*(SigF^2)) / ^2). " - "Default value is alpha=0, e.g., no weighting is performed. " - ) - ) - - parser.add_argument( - "--unmasked-radius", - required=False, - type=float, - default=5, - help=( - "Maximum distance (in Anstroms) away from protein model to include voxels. Only applies to the 'unmasked' difference map output. " - "Defaults to 5. " - "Note that the regular difference map (e.g. the 'masked' version) is not affected by this parameter and maintains a solvent mask radius of 2 Angstroms." - ), - ) - - parser.add_argument( - "--verbose", - "-v", - required=False, - action="store_true", - default=False, - help="Include this flag to print out scaleit and phenix.refine outputs to the terminal. Useful for troubleshooting, but annoying; defaults to False.", - ) - - parser.add_argument( - "--rbr-selections", - "-r", - required=False, - default=None, - nargs="*", - help=( - "Specification of multiple rigid-body groups for refinement. By default, everything is refined as one rigid-body group. " - ), - ) - - parser.add_argument( - "--eff", - required=False, - default=None, - help=("Custom .eff template for running phenix.refine. "), - ) - - parser.add_argument( - "--keep-temp-files", - "-k", - required=False, - default=None, - help=( - "Do not delete intermediate matchmaps files, but rather place them in the supplied directory. " - "This directory is created as a subdirectory of the supplied output-dir." - ) - ) - - parser.add_argument( - "--script", - required=False, - default='run_matchmaps', - help=( - "Name for a file {script}.sh which can be run to repeat this command. " - "By default, this file is called `run_matchmaps.sh`. " - "Note that this file is written out in the current working directory, NOT the input or output directories" - ) - ) - - parser.add_argument( - "--phenix-version", - required=False, - help=( - "Specify phenix version as a string, e.g. '1.20'. " - "If omitted, matchmaps will attempt to automatically detect the version in use " - "by analyzing the output of phenix.version" - ) - ) - - return parser - - def main(): - parser = parse_arguments() - args = parser.parse_args() + args = matchmaps_parser.parse_args() (input_dir, output_dir, ligands, mtzoff, mtzon, pdboff) = _validate_inputs( args.input_dir, From 5da1265fd5938456c32baa39e52b0765c5d9e3a7 Mon Sep 17 00:00:00 2001 From: dennisbrookner Date: Tue, 18 Jun 2024 12:19:57 -0400 Subject: [PATCH 5/5] use new parsers for building docs --- docs/cli.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 3ccc7a4..80d7d14 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -3,12 +3,12 @@ `matchmaps` is built to be used from the command-line. See the following utilities below. You can also print these messages in the command-line via the `--help` option. ```{eval-rst} -.. autoprogram:: matchmaps._compute_realspace_diff:parse_arguments() +.. autoprogram:: matchmaps._parsers:matchmaps_parser :prog: matchmaps -.. autoprogram:: matchmaps._compute_ncs_diff:parse_arguments() - :prog: matchmaps.ncs - -.. autoprogram:: matchmaps._compute_mr_diff:parse_arguments() +.. autoprogram:: matchmaps._parsers:matchmaps_mr_parser :prog: matchmaps.mr + +.. autoprogram:: matchmaps._parsers:matchmaps_ncs_parser + :prog: matchmaps.ncs ```