Skip to content

Commit

Permalink
Refactor out hierarchy.input usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
olegsobolev committed Mar 9, 2023
1 parent b9381a6 commit 7da1ab5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 50 deletions.
5 changes: 2 additions & 3 deletions mmtbx/refinement/ensemble_refinement/ensemble_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from iotbx.option_parser import iotbx_option_parser
from mmtbx import utils
from iotbx import file_reader
from iotbx.pdb import hierarchy
import iotbx.phil
import libtbx.phil
from libtbx.utils import Sorry
Expand Down Expand Up @@ -350,10 +349,10 @@ def run(self, args, command_name, out=sys.stdout):
# process PDB
pdb_file.assert_file_type("pdb")
#
pdb_in = hierarchy.input(file_name=pdb_file.file_name)
pdb_in = pdb.input(file_name=pdb_file.file_name)
ens_pdb_hierarchy = pdb_in.construct_hierarchy()
ens_pdb_hierarchy.atoms().reset_i_seq()
ens_pdb_xrs_s = pdb_in.input.xray_structures_simple()
ens_pdb_xrs_s = pdb_in.xray_structures_simple()
number_structures = len(ens_pdb_xrs_s)
print('Number of structure in ensemble : ', number_structures, file=self.log)

Expand Down
4 changes: 2 additions & 2 deletions mmtbx/refinement/real_space/tst_flipbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def exercise():
crystal_symmetry=xrs_good.crystal_symmetry())

def exercise2():
pdb_in = iotbx.pdb.hierarchy.input(pdb_string="""\
pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM 3988 P DA G 10 2.095 -23.407 14.671 1.00 24.76 P
ATOM 3989 OP1 DA G 10 2.702 -22.768 13.479 1.00 24.54 O
ATOM 3990 OP2 DA G 10 1.098 -22.688 15.497 1.00 26.02 O
Expand All @@ -172,7 +172,7 @@ def exercise2():
ATOM 4008 C4 DA G 10 7.629 -27.865 15.998 1.00 13.67 C
""")
#open("tmp1.pdb", "w").write(pdb_in.hierarchy.as_pdb_string())
base = pdb_in.hierarchy.only_atom_group()
base = pdb_in.construct_hierarchy().only_atom_group()
xyz = base.atoms().extract_xyz().deep_copy()
flipbase.flip_base(base, angle=180)
xyz_new = base.atoms().extract_xyz()
Expand Down
27 changes: 12 additions & 15 deletions mmtbx/refinement/tst_select_best_starting_model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

from __future__ import absolute_import, division, print_function

from libtbx.test_utils import Exception_expected
from libtbx.utils import null_out, Sorry
from libtbx import easy_run
from scitbx.array_family import flex
from cctbx import uctbx, sgtbx
import iotbx.pdb
from iotbx import file_reader
from mmtbx.refinement import select_best_starting_model
import random
from six.moves import range

def exercise_main():
from mmtbx.refinement import select_best_starting_model
from iotbx import file_reader
from cctbx import uctbx
from cctbx import sgtbx
from scitbx.array_family import flex
import random
unit_cell = (24.937, 8.866, 25.477, 90.00, 107.08, 90.00)
space_group = "P21"
pdb_base = """\
Expand Down Expand Up @@ -194,9 +194,6 @@ def random_double(size, factor=1):
assert (result.best_model_name == "tst_start_model_1.pdb"), result.best_model_name

def exercise_misc():
from mmtbx.refinement import select_best_starting_model
from iotbx import file_reader
import iotbx.pdb.hierarchy
pdb_str = """\
REMARK this is a remark record!
CRYST1 21.937 4.866 23.477 90.00 107.08 90.00 P 1 21 1
Expand Down Expand Up @@ -335,9 +332,9 @@ def exercise_misc():
pdb_file = "tst_start_model_misc.pdb"
with open(pdb_file, "w") as f:
f.write(pdb_str)
pdb_in = iotbx.pdb.hierarchy.input(pdb_file)
pdb_hierarchy = pdb_in.hierarchy
xray_structure = pdb_in.input.xray_structure_simple()
pdb_in = iotbx.pdb.input(file_name=pdb_file)
pdb_hierarchy = pdb_in.construct_hierarchy()
xray_structure = pdb_in.xray_structure_simple()
hd_sel = xray_structure.hd_selection()
assert hd_sel.count(True) == 55
xray_structure.convert_to_anisotropic(selection=~hd_sel)
Expand Down Expand Up @@ -405,8 +402,8 @@ def exercise_misc():
preserve_remarks=True,
output_file="tst_start_model_misc_new.pdb",
log=null_out())
pdb_new = iotbx.pdb.hierarchy.input(file_name="tst_start_model_misc_new.pdb")
assert len(pdb_new.input.remark_section()) == 1
pdb_new = iotbx.pdb.input(file_name="tst_start_model_misc_new.pdb")
assert len(pdb_new.remark_section()) == 1
# reset HETATM
hierarchy_new, xrs_new = select_best_starting_model.strip_model(
file_name=pdb_file,
Expand Down
6 changes: 3 additions & 3 deletions mmtbx/scaling/tst_xtriage_twin_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import absolute_import, division, print_function
from mmtbx.scaling import twin_analyses
import iotbx.pdb.hierarchy
import iotbx.pdb
from scitbx.array_family import flex
from libtbx.test_utils import approx_equal, show_diff
from libtbx.utils import null_out
Expand Down Expand Up @@ -61,8 +61,8 @@ def exercise_twin_detection(verbose=False):
ATOM 21 OXT TYR B 7 7.316 5.408 8.654 1.00 18.49 O
END
"""
pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_str)
xrs = pdb_in.input.xray_structure_simple()
pdb_in = iotbx.pdb.input(source_info=None, lines=pdb_str)
xrs = pdb_in.xray_structure_simple()
fc = abs(xrs.structure_factors(d_min=2.5).f_calc())
fc = fc.set_observation_type_xray_amplitude()
sigf = flex.double(fc.size(), 0.1) + (fc.data() * 0.03)
Expand Down
44 changes: 22 additions & 22 deletions mmtbx/secondary_structure/tst_insertion_codes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

from __future__ import absolute_import, division, print_function
from mmtbx.secondary_structure import sec_str_master_phil_str, manager
import iotbx.pdb.hierarchy
import iotbx.pdb
import iotbx.pdb.secondary_structure as ioss
from libtbx.utils import null_out


def exercise_helix_bonding_pattern_with_insertions():
alpha_h1_ends = iotbx.pdb.hierarchy.input(pdb_string="""\
alpha_h1_ends = iotbx.pdb.input(source_info=None, lines="""\
ATOM 1 N ALA 1 1.643 -2.366 -1.408 1.00 0.00 N
ATOM 2 CA ALA 1 1.280 -3.608 -2.069 1.00 0.00 C
ATOM 3 C ALA 1 -0.114 -3.466 -2.684 1.00 0.00 C
Expand Down Expand Up @@ -59,9 +59,9 @@ def exercise_helix_bonding_pattern_with_insertions():
ATOM 49 O ALA 9A -5.880 -1.605 -16.177 1.00 0.00 O
ATOM 50 CB ALA 9A -5.358 0.040 -13.274 1.00 0.00 C
TER
""")
""").construct_hierarchy()

alpha_h1_ac = iotbx.pdb.hierarchy.input(pdb_string="""\
alpha_h1_ac = iotbx.pdb.input(source_info=None, lines="""\
ATOM 1 N AALA 1 1.643 -2.366 -1.408 0.50 0.00 N
ATOM 2 CA AALA 1 1.280 -3.608 -2.069 0.50 0.00 C
ATOM 3 C AALA 1 -0.114 -3.466 -2.684 0.50 0.00 C
Expand Down Expand Up @@ -128,7 +128,7 @@ def exercise_helix_bonding_pattern_with_insertions():
ATOM 65 O BALA 9A -5.780 -1.605 -16.177 0.50 0.00 O
ATOM 66 CB BALA 9A -5.258 0.040 -13.274 0.50 0.00 C
END
""")
""").construct_hierarchy()

alpha_annot_1_1 = """\
HELIX 1 1 ALA 1 ALA 9A 1 10
Expand All @@ -150,7 +150,7 @@ def exercise_helix_bonding_pattern_with_insertions():
log = null_out()
n_hbonds = []
n_hangles = []
for pdb_inp, recs in [
for pdb_h, recs in [
(alpha_h1_ends, alpha_annot_1_1), #6
(alpha_h1_ends, alpha_annot_1_2), #4
(alpha_h1_ends, alpha_annot_1_3), #5
Expand All @@ -166,7 +166,7 @@ def exercise_helix_bonding_pattern_with_insertions():
custom_pars = defpars.fetch(iotbx.phil.parse(ann))
custom_pars_ex = custom_pars.extract()
ss_manager = manager(
pdb_inp.hierarchy,
pdb_h,
sec_str_from_pdb_file=None,
params=custom_pars_ex.secondary_structure,
verbose=-1)
Expand All @@ -180,7 +180,7 @@ def exercise_helix_bonding_pattern_with_insertions():
assert n_hangles == [18, 12, 15, 15, 28, 16, 22, 22]

def exercise_sheets_bonding_pattern_with_insertions():
pdb_apar_input = iotbx.pdb.hierarchy.input(pdb_string = """\
pdb_apar_h = iotbx.pdb.input(source_info=None, lines = """\
SCRYST1 46.460 46.460 193.210 90.00 90.00 120.00 P 31 2 1
SCALE1 0.021524 0.012427 0.000000 0.00000
SCALE2 0.000000 0.024854 0.000000 0.00000
Expand Down Expand Up @@ -268,9 +268,9 @@ def exercise_sheets_bonding_pattern_with_insertions():
ATOM 237 O SER A 35A 24.929 -22.095 -0.497 1.00 6.22 O
ATOM 238 CB SER A 35A 23.881 -21.071 -3.639 1.00 5.69 C
ATOM 239 OG SER A 35A 25.213 -20.561 -3.633 1.00 7.12 O
""")
""").construct_hierarchy()

pdb_par_input = iotbx.pdb.hierarchy.input(pdb_string = """\
pdb_par_h = iotbx.pdb.input(source_info=None, lines = """\
CRYST1 46.460 46.460 193.210 90.00 90.00 120.00 P 31 2 1
SCALE1 0.021524 0.012427 0.000000 0.00000
SCALE2 0.000000 0.024854 0.000000 0.00000
Expand Down Expand Up @@ -346,9 +346,9 @@ def exercise_sheets_bonding_pattern_with_insertions():
ATOM 223 CB ALA A 45A 6.607 -27.026 -9.678 1.00 4.52 C
TER
END
""")
""").construct_hierarchy()

pdb_par_ac_input = iotbx.pdb.hierarchy.input(pdb_string = """\
pdb_par_ac_h = iotbx.pdb.input(source_info=None, lines = """\
CRYST1 46.460 46.460 193.210 90.00 90.00 120.00 P 31 2 1
SCALE1 0.021524 0.012427 0.000000 0.00000
SCALE2 0.000000 0.024854 0.000000 0.00000
Expand Down Expand Up @@ -434,7 +434,7 @@ def exercise_sheets_bonding_pattern_with_insertions():
ATOM 79 CB ALA A 46 6.607 -27.026 -9.678 1.00 4.52 C
TER 80 ALA A 46
END
""")
""").construct_hierarchy()

s_apar_records1 = """\
SHEET 1 A 2 TYR A 2 VAL A 7 0
Expand Down Expand Up @@ -466,22 +466,22 @@ def exercise_sheets_bonding_pattern_with_insertions():
# defpars = sec_str_master_phil
n_hbonds = []
n_hangles = []
for pdb_inp, recs in [
(pdb_apar_input, s_apar_records1), # 6
(pdb_apar_input, s_apar_records2), # 6
(pdb_apar_input, s_apar_records3), # 4
(pdb_par_input, s_par_records1), # 6
(pdb_par_input, s_par_records2), # 6
(pdb_par_input, s_par_records3), # 5
(pdb_par_ac_input, s_par_records1), # 8 hbonds
for pdb_h, recs in [
(pdb_apar_h, s_apar_records1), # 6
(pdb_apar_h, s_apar_records2), # 6
(pdb_apar_h, s_apar_records3), # 4
(pdb_par_h, s_par_records1), # 6
(pdb_par_h, s_par_records2), # 6
(pdb_par_h, s_par_records3), # 5
(pdb_par_ac_h, s_par_records1), # 8 hbonds
]:
ioss_annotation = ioss.annotation.from_records(records = recs.split('\n'))
ann = ioss_annotation.as_restraint_groups(prefix_scope="secondary_structure")
defpars = iotbx.phil.parse(sec_str_master_phil_str)
custom_pars = defpars.fetch(iotbx.phil.parse(ann))
custom_pars_ex = custom_pars.extract()
ss_manager = manager(
pdb_inp.hierarchy,
pdb_h,
sec_str_from_pdb_file=None,
params=custom_pars_ex.secondary_structure,
verbose=-1)
Expand Down
5 changes: 0 additions & 5 deletions sphinx/iotbx/iotbx.pdb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ API documentation
Input methods and objects
-------------------------

.. autoclass:: iotbx.pdb.hierarchy.input
:members:
:undoc-members:
:show-inheritance:

.. autofunction:: iotbx.pdb.input

.. autoclass:: iotbx.pdb.ext.input
Expand Down

0 comments on commit 7da1ab5

Please sign in to comment.