Skip to content

Commit

Permalink
Merge pull request #53 from rs-station/phenix121
Browse files Browse the repository at this point in the history
Add support for phenix 1.21
  • Loading branch information
dennisbrookner authored Jun 3, 2024
2 parents f9e3c70 + ebcad70 commit be8c2f2
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 346 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ docs/images/logo.ai
docs/images/logo2.ai

# PyCharm files
.idea/*
.idea/*
.idea/*
45 changes: 26 additions & 19 deletions src/matchmaps/_compute_mr_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
import argparse
import os
import sys
import subprocess
import time
from functools import partial
from pathlib import Path

import gemmi
import numpy as np
import reciprocalspaceship as rs

from matchmaps._phenix_utils import rigid_body_refinement_wrapper, phaser_wrapper, _remove_waters
from matchmaps._utils import (
_handle_special_positions,
make_floatgrid_from_mtz,
rigid_body_refinement_wrapper,
_realspace_align_and_subtract,
_rbr_selection_parser,
_remove_waters,
_restore_ligand_occupancy,
_validate_environment,
_validate_inputs,
phaser_wrapper,
_clean_up_files,
_cif_or_pdb_to_pdb,
_cif_or_mtz_to_mtz,
Expand Down Expand Up @@ -51,7 +46,8 @@ def compute_mr_difference_map(
radius : float = 5,
alpha : float = 0,
no_bss = False,
):
phenix_version: str = None,
):
"""
Compute a real-space difference map from mtzs in different spacegroups.
Expand Down Expand Up @@ -105,7 +101,12 @@ def compute_mr_difference_map(
If True, skip bulk solvent scaling feature of phenix.refine
"""

_validate_environment(ccp4=False)
auto_phenix_version = _validate_environment(ccp4=False)

if phenix_version:
pass
else:
phenix_version = auto_phenix_version

output_dir_contents = list(output_dir.glob("*"))

Expand All @@ -130,15 +131,8 @@ def compute_mr_difference_map(
f"{time.strftime('%H:%M:%S')}: Running phenix.phaser to place 'off' model into 'on' data..."
)

phaser_nickname = phaser_wrapper(
mtzfile=mtzon,
pdb=pdboff,
input_dir=input_dir,
output_dir=output_dir,
off_labels=f"{Fon},{SigFon}",
eff=None,
verbose=verbose,
)
phaser_nickname = phaser_wrapper(mtzfile=mtzon, pdb=pdboff, output_dir=output_dir, off_labels=f"{Fon},{SigFon}",
phenix_style=phenix_version, eff=None, verbose=verbose)

# TO-DO: fix ligand occupancies in pdb_mr_to_on
edited_mr_pdb = _restore_ligand_occupancy(
Expand All @@ -161,6 +155,7 @@ def compute_mr_difference_map(
off_labels=f"{Fon},{SigFon}", # workaround for compatibility
mr_on=True,
no_bss=no_bss,
phenix_style=phenix_version,
)

print(f"{time.strftime('%H:%M:%S')}: Running phenix.refine for the 'off' data...")
Expand All @@ -175,8 +170,8 @@ def compute_mr_difference_map(
verbose=verbose,
rbr_selections=rbr_phenix,
off_labels=f"{Foff},{SigFoff}",
mr_off=True,
no_bss=no_bss,
phenix_style=phenix_version,
)

# from here down I just copied over the stuff from the normal version
Expand Down Expand Up @@ -443,6 +438,16 @@ def parse_arguments():
)
)

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


Expand Down Expand Up @@ -485,14 +490,16 @@ def main():
alpha=args.alpha,
on_as_stationary=args.on_as_stationary,
keep_temp_files=args.keep_temp_files,
no_bss = args.no_bss
no_bss = args.no_bss,
phenix_version = args.phenix_version,
)

if args.script:
_write_script(
utility = 'matchmaps.mr',
arguments = sys.argv[1:],
script_name = args.script,
phenix_version=args.phenix_version,
)

return
Expand Down
33 changes: 23 additions & 10 deletions src/matchmaps/_compute_ncs_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
import argparse
import os
import sys
import subprocess
import time
from functools import partial
from pathlib import Path

import gemmi
import numpy as np
import reciprocalspaceship as rs


from matchmaps._phenix_utils import rigid_body_refinement_wrapper, _renumber_waters
from matchmaps._utils import (
_handle_special_positions,
make_floatgrid_from_mtz,
rigid_body_refinement_wrapper,
_realspace_align_and_subtract,
_rbr_selection_parser,
_renumber_waters,
_ncs_align_and_subtract,
_validate_environment,
_validate_inputs,
Expand Down Expand Up @@ -48,6 +42,7 @@ def compute_ncs_difference_map(
eff : str = None,
keep_temp_files : str = None,
no_bss = False,
phenix_version: str = None,
):
"""
Compute an internal difference map across non-crystallographic symmetry
Expand Down Expand Up @@ -91,8 +86,13 @@ def compute_ncs_difference_map(
no_bss : bool, optional
If True, skip bulk solvent scaling feature of phenix.refine
"""
_validate_environment(ccp4=False)

auto_phenix_version = _validate_environment(ccp4=False)

if phenix_version:
pass
else:
phenix_version = auto_phenix_version

output_dir_contents = list(output_dir.glob("*"))

pdb = _cif_or_pdb_to_pdb(pdb, output_dir)
Expand Down Expand Up @@ -121,7 +121,8 @@ def compute_ncs_difference_map(
verbose=verbose,
rbr_selections=rbr_phenix,
off_labels=f"{F},{SigF}",
no_bss=no_bss
no_bss=no_bss,
phenix_style=phenix_version,
)

# use phenix names for columns when computing FloatGrid
Expand Down Expand Up @@ -327,6 +328,16 @@ def parse_arguments():
"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

Expand Down Expand Up @@ -366,13 +377,15 @@ def main():
spacing=args.spacing,
keep_temp_files=args.keep_temp_files,
no_bss=args.no_bss,
phenix_version=args.phenix_version,
)

if args.script:
_write_script(
utility = 'matchmaps.ncs',
arguments = sys.argv[1:],
script_name = args.script,
phenix_version=args.phenix_version,
)

return
Expand Down
37 changes: 26 additions & 11 deletions src/matchmaps/_compute_realspace_diff.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
"""Compute unbiased real space difference map."""

import argparse
import os
import sys
import glob
import subprocess
import sys
import time
from functools import partial
from pathlib import Path

import gemmi
import numpy as np
import reciprocalspaceship as rs

from IPython import embed

from matchmaps._phenix_utils import rigid_body_refinement_wrapper, _renumber_waters
from matchmaps._utils import (
_handle_special_positions,
make_floatgrid_from_mtz,
rigid_body_refinement_wrapper,
_realspace_align_and_subtract,
_rbr_selection_parser,
_renumber_waters,
_clean_up_files,
_validate_environment,
_validate_inputs,
Expand Down Expand Up @@ -51,7 +44,8 @@ def compute_realspace_difference_map(
keep_temp_files : str = None,
radius : float = 5,
alpha : float = 0,
no_bss = False
no_bss = False,
phenix_version: str = None,
):
"""
Compute a real-space difference map from mtzs.
Expand Down Expand Up @@ -103,9 +97,16 @@ def compute_realspace_difference_map(
Alpha to use in error weighting of F-obs prior to Fourier Transform. Defaults to 0, e.g. no weighting.
no_bss : bool, optional
If True, skip bulk solvent scaling feature of phenix.refine
phenix_version: str, optional
Phenix version string to override the automatically detected version. I don't know why this would be necessary.
"""

_validate_environment(ccp4=True)
auto_phenix_version = _validate_environment(ccp4=True)

if phenix_version:
pass
else:
phenix_version = auto_phenix_version

output_dir_contents = list(output_dir.glob("*"))

Expand Down Expand Up @@ -173,6 +174,7 @@ def compute_realspace_difference_map(
verbose=verbose,
rbr_selections=rbr_phenix,
no_bss=no_bss,
phenix_style=phenix_version,
)

print(f"{time.strftime('%H:%M:%S')}: Running phenix.refine for the 'off' data...")
Expand All @@ -188,6 +190,7 @@ def compute_realspace_difference_map(
rbr_selections=rbr_phenix,
off_labels=f"{Foff},{SigFoff}",
no_bss=no_bss,
phenix_style=phenix_version,
)

# read back in the files created by phenix
Expand Down Expand Up @@ -446,6 +449,16 @@ def parse_arguments():
"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

Expand Down Expand Up @@ -484,13 +497,15 @@ def main():
on_as_stationary=args.on_as_stationary,
keep_temp_files=args.keep_temp_files,
no_bss = args.no_bss,
phenix_version = args.phenix_version,
)

if args.script:
_write_script(
utility = 'matchmaps',
arguments = sys.argv[1:],
script_name = args.script,
phenix_version=args.phenix_version,
)

return
Expand Down
Loading

0 comments on commit be8c2f2

Please sign in to comment.