Skip to content

Commit

Permalink
Merge pull request #418 from ExcitedStates/qfit_em_refine
Browse files Browse the repository at this point in the history
re-write em refinement
  • Loading branch information
Stephanie (Mullane) Wankowicz committed Apr 25, 2024
2 parents 7c9c235 + 0142aa0 commit 1993f82
Showing 1 changed file with 20 additions and 66 deletions.
86 changes: 20 additions & 66 deletions scripts/post/qfit_final_refine_cryoem.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

'''
This script works with Phenix version 1.18.
This script works with Phenix version 1.21dev.
'''

qfit_usage() {
echo >&2 "Usage:";
echo >&2 " $0 mapfile.ccp4 originalmodel.pdb [multiconformer_model2.pdb]";
echo >&2 " $0 mapfile.ccp4 [multiconformer_model2.pdb]";
echo >&2 "";
echo >&2 "mapfile.ccp4, originalmodel.pdb, multiconformer_model2.pdb MUST exist in this directory.";
echo >&2 "mapfile.ccp4, multiconformer_model2.pdb MUST exist in this directory.";
echo >&2 "Outputs will be written to mapfile_qFit.{pdb|mtz|log}.";
exit 1;
}
Expand All @@ -33,23 +33,22 @@ command -v remove_duplicates >/dev/null 2>&1 || {

# Assert required files exist
mapfile=$1
org_model=$2
res=$2
multiconf=${3:-multiconformer_model2.pdb}

echo "mapfile : ${mapfile} $([[ -f ${mapfile} ]] || echo '[NOT FOUND]')";
echo "original model : ${org_model} $([[ -f ${org_model} ]] || echo '[NOT FOUND]')";
echo "mapfile: ${mapfile} $([[ -f ${mapfile} ]] || echo '[NOT FOUND]')";
if [ -z "${res}" ]; then
echo >&2 "Resolution not specified.";
exit 1;
fi
echo "resolution : ${res}";
echo "qfit unrefined model : ${multiconf} $([[ -f ${multiconf} ]] || echo '[NOT FOUND]')";
echo "";
if [[ ! -f "${mapfile}" ]] || [[ ! -f "${multiconf}" ]] || [[ -f ${org_model} ]]; then
if [[ ! -f "${mapfile}" ]] || [[ ! -f "${multiconf}" ]]; then
qfit_usage;
fi
pdb_name="${mapfile%.ccp4}"
echo $pdb_name
#__________________________________DETERMINE RESOLUTION AND (AN)ISOTROPIC REFINEMENT__________________________________
resolution=$(grep 'REMARK 3 RESOLUTION RANGE HIGH (ANGSTROMS) :' $org_model)
echo $resolution
res=`echo "${resolution}" | cut -d " " -f 14 | cut -c 1-5`
echo "Resolution: ${res}"

#__________________________________REMOVE DUPLICATE HET ATOMS__________________________________
remove_duplicates "${multiconf}"
Expand All @@ -62,34 +61,7 @@ phenix.ready_set hydrogens=false \
trust_residue_code_is_chemical_components_code=true \
pdb_file_name="${multiconf}.f_modified.pdb"

#__________________________________REFINEMENT WITHOUT HYDROGENS__________________________________
if [ -f "${multiconf}.f_modified.ligands.cif" ]; then
echo "with ligand"
phenix.real_space_refine "${multiconf}.f_modified.updated.pdb" \
"${pdb_name}.ccp4" \
"${multiconf}.f_modified.ligands.cif" \
output.file_name_prefix="${pdb_name}2" \
macro_cycles=5 \
resolution=${res} \
--overwrite
else
phenix.real_space_refine "${multiconf}.f_modified.pdb" \
"${pdb_name}.ccp4" \
output.file_name_prefix="${pdb_name}2" \
macro_cycles=5 \
resolution=${res} \
--overwrite
fi

#__________________________________ADD HYDROGENS__________________________________
# The first round of refinement regularizes geometry from qFit.
# Here we add H with phenix.reduce. Addition of H to the backbone is important
# since it introduces planarity restraints to the peptide bond.
# This helps to prevent backbone conformers from being merged during
# subsequent rounds of refinement.
cp "${pdb_name}2_real_space_refined.001.pdb" "${pdb_name}2.000.pdb"
phenix.reduce "${pdb_name}2.000.pdb" > "${pdb_name}2_real_space_refined.001.pdb"

cp ${multiconf}.f_modified.pdb ${pdb_name}2_real_space_refined.001.pdb
#__________________________________REFINE UNTIL OCCUPANCIES CONVERGE__________________________________
zeroes=50
i=1
Expand All @@ -100,51 +72,33 @@ while [ $zeroes -gt 1 ]; do
phenix.real_space_refine "${pdb_name}2_real_space_refined.001.pdb" \
"${pdb_name}.ccp4" \
"${multiconf}.f_modified.ligands.cif" \
output.file_name_prefix="${pdb_name}3" \
output.prefix="${pdb_name}3" \
macro_cycles=5 \
resolution=${res} \
--overwrite
else
phenix.real_space_refine "${pdb_name}2_real_space_refined.001.pdb" \
"${pdb_name}.ccp4" \
output.file_name_prefix="${pdb_name}3" \
output.prefix="${pdb_name}3" \
macro_cycles=5 \
resolution=${res} \
--overwrite
fi

zeroes=`redistribute_cull_low_occupancies -occ 0.09 "${pdb_name}3_real_space_refined.pdb" | tail -n 1`
zeroes=`redistribute_cull_low_occupancies -occ 0.09 "${pdb_name}3_real_space_refined_000.pdb" | tail -n 1`
echo "Post refinement zeroes: ${zeroes}"

if [ ! -f "${pdb_name}3_real_space_refined_norm.pdb" ]; then
if [ ! -f "${pdb_name}3_real_space_refined_000_norm.pdb" ]; then
echo >&2 "Normalize occupancies did not work!";
exit 1;
else
mv "${pdb_name}3_real_space_refined_norm.pdb" "${pdb_name}2_real_space_refined.001.pdb"
mv "${pdb_name}3_real_space_refined_000_norm.pdb" "${pdb_name}2_real_space_refined.001.pdb"
fi

done

#__________________________________FINAL REFINEMENT__________________________________
mv "${pdb_name}2_real_space_refined.001.pdb" "${pdb_name}4_real_space_refined.001.pdb"
if [ -f "${multiconf}.f_modified.ligands.cif" ]; then
phenix.real_space_refine "${pdb_name}4_real_space_refined.001.pdb" \
"${pdb_name}.ccp4" \
"${multiconf}.f_modified.ligands.cif" \
output.file_name_prefix="${pdb_name}5" \
macro_cycles=5 \
resolution=${res} \
--overwrite
else
phenix.real_space_refine "${pdb_name}4_real_space_refined.001.pdb" \
"${pdb_name}.ccp4" \
output.file_name_prefix="${pdb_name}5" \
macro_cycles=5 \
resolution=${res} \
--overwrite
fi


#__________________________________NAME FINAL FILES__________________________________
cp "${pdb_name}5_real_space_refined.pdb" "${pdb_name}_qFit.pdb"
cp "${pdb_name}2_real_space_refined.001.pdb" "${pdb_name}_qFit.pdb"
cp "${pdb_name}.ccp4" "${pdb_name}_qFit.ccp4"
cp "${pdb_name}5_real_space_refined.log" "${pdb_name}_qFit.log"
cp "${pdb_name}2_real_space_refined.001.log" "${pdb_name}_qFit.log"

0 comments on commit 1993f82

Please sign in to comment.