This section summarizes some commonly-used functions in Phenix and cctbx.
phenix.setup_tutorial tutorial_name=model-building-scripting
from iotbx.data_manager import DataManager # Load in the DataManager
dm = DataManager() # Initialize the DataManager and call it dm
dm.set_overwrite(True) # Overwrite files with the same name
help(dm)
help(dm.get_map_model_manager)
mmm_ligand = dm.get_map_model_manager( # get map_model manager
model_file="boxed_ligand_map.pdb", # model file
map_files="boxed_ligand_map.ccp4") # map file
model_for_morphing = dm.get_model("short_model_box_for_morph.pdb") # model
model_for_sequence = dm.get_model("short_model_main_chain_box.pdb") # model
original_model_for_morphing = model_for_morphing.deep_copy() # copy of model
model_atp = dm.get_model("atp.pdb") # model file
dm.process_restraint_file("atp.cif") # Set up restraints
restraints_atp=dm.get_restraint("atp.cif") # get a restraints object
mm = dm.get_real_map("boxed_ligand_map.ccp4") # map file
mm_for_morphing = dm.get_real_map("short_model_box.ccp4") # another map file
dm.remove_real_map("short_model_box.ccp4") # remove map from data_manager
mmm_map_only = dm.get_map_model_manager( # get map_model manager
map_files="short_model_box.ccp4") # map file
mm.set_wrapping(False) # do not wrap (do not extend outside supplied map)
mm.set_experiment_type("xray") # alternatives are cryo_em or neutron
mm.set_scattering_table("n_gaussian") # electron/neutron/wk1995/it1992
ncs_d7 = dm.get_ncs_spec("D7.ncs_spec") # reconstruction symmetry file
map_manager = mm_for_morphing.deep_copy() # use a separate copy
model = model_for_morphing.deep_copy() # model, also a separate copy
from iotbx.map_model_manager import map_model_manager # import manager
mmm = map_model_manager(map_manager = map_manager, model = model) #
map_manager = mm_for_morphing.deep_copy() # use a separate copy
model = model_for_morphing.deep_copy() # model, also a separate copy
from iotbx.map_model_manager import map_model_manager # import manager
mmm_ncs = map_model_manager(map_manager = map_manager, model = model, #
ncs_object = ncs_d7) # reconstruction symmetry
model_1 = model.deep_copy() # copy of a model
map_manager.shift_model_to_match_map(model_1) # shift model_1 to match map
mmm_copy = mmm.deep_copy() # deep copy of a map-model manager
mmm.set_resolution(3) # set default resolution to 3 A
mmm.set_experiment_type("xray") # alternatives are cryo_em/neutron
dm = DataManager() # Initialize the DataManager and call it dm
dm.set_overwrite(True)
model = dm.get_model("structure_search_target.pdb") # read in a model
model_mmm = dm.get_map_model_manager( # getting a map_model_manager
model_file = "structure_search_target.pdb",) # model to read in
model_mmm.generate_map(d_min=3) # generate map to resolution of 3 A
build = mmm.model_building() # get model_building object
new_mmm = build.as_map_model_manager() # get map-model manager
mm = build.map_manager() # map_manager from model-building object
model = build.model() # model from model-building object
mm = mmm.map_manager() # map_manager from map-model manager
model = mmm.model() # model from map-model manager
for file_name in dm.get_real_map_names(): # list of previously read maps
dm.remove_real_map(file_name) # forget previous reads
mm = dm.get_real_map("boxed_ligand_map.ccp4") # read in map file
copy_of_mm = mm.deep_copy() # Separate copy of map_data
mm.shift_origin() # shift origin to (0,0,0)
mm1 = copy_of_mm.deep_copy() # map manager to work with
mm1.shift_origin_to_match_original() # put origin back where it was
dir(mm) # list all the methods available for mm
mm.set_resolution(3) # nominal resolution is 3 A;
mm.set_experiment_type("xray") # alternatives are cryo_em/neutron
mm.set_scattering_table("n_gaussian") # electron/neutron/wk1995/it1992
shift_cart = mm.shift_cart() # shift since start
origin_shift_grid_units = mm.origin_shift_grid_units # origin pos
n_real = mm.map_data().all() # gridding of working map
wrapping = mm.wrapping() # wrapping of working map
is_full_size = mm.is_full_size() # is map full size (not boxed)
is_zero_based = mm.origin_is_zero() # is zero-based
is_consistent_with_wrapping = mm.is_consistent_with_wrapping() # ok to wrap
is_similar = mm.is_similar(mm1) # map_managers are similar
map_data = mm.map_data() # map_data
some_map_data = mm.map_data() + 5 # some map_data
new_mm = mm.customized_copy(map_data = some_map_data) # new map manager
new_mm.set_map_data(map_data = map_data) # new_mm data is now map_data
# Note: change new_mm and you are also changing map_data
new_mm.initialize_map_data() # set values of map_data in new_mm to zero
full_size = mm.as_full_size_map() # full size version padded with zero
n_real = mm.map_data().all() # current gridding
new_n_real = [n_real[0],n_real[1],n_real[2] * 2] # double gridding along c
resampled = mm.resample_on_different_grid(new_n_real) # resample
cc = mm.cc_to_other_map_manager(new_mm) # map correlation to other map
low_res_map = mm.resolution_filter(10) # 10 A map
gaussian_blur = mm.gaussian_filter(1) # blur with 1 A Gaussian
binary_filtered = mm.binary_filter(threshold = 0.5) # set value to 1 if
# average of 27 in box around this point > 0.5
mm.create_mask_around_density(resolution = 3) # mask around density
mm.create_mask_around_edges(soft_mask_radius = 3) # mask around edges
model = dm.get_model("structure_search_target.pdb") # get a model
mm.create_mask_around_atoms(model = model) # radius=max(resolution,3)
mm.soft_mask() # make the mask a soft mask. Default radius is resolution
mm.apply_mask() # apply the mask to working map (changes working map)
mask_as_map_manager = mm.get_mask_as_map_manager() # mask as a map manager
sites_cart = model.get_sites_cart() # some coordinates
density_values = mm.density_at_sites_cart(sites_cart) # density at coords
mm.set_mean_zero_sd_one() # normalize map
mm.find_map_symmetry() # find map symmetry
ncs_obj = mm.ncs_object() # get the map symmetry as an ncs object
sites_cart = mm.find_n_highest_grid_points_as_sites_cart() # highest points
sites_cart = mm.trace_atoms_in_map(dist_min = 2, n_atoms = 31) # separated
# sites in density
map_coeffs = mm.map_as_fourier_coefficients(d_min = 3) # map coeffs to 3 A
new_mm = mm.fourier_coefficients_as_map_manager(map_coeffs) # new map_manager
copy_of_map_data = map_data.deep_copy() # Separate copy of map_data
print ("Size of almost anything is anything.size(): %s" %(map_data.size()))
pointer_to_map_data = map_data # just an alias to map_data
value = map_data[3,4,5] # get value of map_data at indices 3,4,5
map_data[3,4,5] = value # set value of map_data at indices 3,4,5
sel = (map_data > 0) # array with True at all grid points with map_data > 0
map_data.set_selected(sel, value) # set values where sel is True to value
map_data_1d = map_data.as_1d() # 1-D array containing the data in map_data
from scitbx.array_family import flex # import flex
new_array = flex.double(map_data_1d.size(), 0) # new array of zeroes
acc = map_data.accessor() # get the accessor for our 3d map data
new_array.reshape(acc) # change new_array shape to match map_data
dc = map_data_1d.deep_copy() # copy of map_data_1d
dc = dc * 3 # multiply all values in dc by 3 and make it the new dc
dc *= 3 # multiply all values in dc by 3 and make it the new dc
new_array = dc + (0.5 * dc ) * (dc) # each value in new_array is
# value in dc + 0.5 *value in dc squared
new_array_2 = dc + 0.5 * flex.pow2(dc) # same result
assert new_array == new_array_2 # assert all values in 2 arrays match
m = map_data_1d.min_max_mean()
print ("Min, max, mean: (%.3f, %.3f, %.3f" %(m.min, m.max, m.mean))
sd = map_data_1d.standard_deviation_of_the_sample()
sites_cart = model.get_sites_cart() # coordinates in model. Order as PDB file
sites_frac = model.get_sites_frac() # fractional coordinates
sites_frac = model.crystal_symmetry().unit_cell().fractionalize(sites_cart) #
sites_cart = model.crystal_symmetry().unit_cell().orthogonalize(sites_frac) #
for x,y,z in sites_cart[:10]: # go through sites_cart
print ("SITE: (%.3f, %.3f, %.3f)" %(x,y,z)) # print them out
model = dm.get_model("structure_search_target.pdb") # read in model
part_of_model = model.apply_selection_string('resseq 6:25') # select part
sel = model.selection('resseq 6:25') # get a selection array
part_of_model = model.select(sel) # apply the selection
min_xyz = sites_cart.min() # lowest value of x, of y, and of z (3 numbers)
max_xyz = sites_cart.max() # highest value of x, of y, and of z (3 numbers)
distances = sites_cart.norms() # distances from origin
sites_cart_2 = sites_cart.reversed() # just something different
diffs = (sites_cart - sites_cart_2) # difference vectors
distances = diffs.norms() # distances between sites_cart and sites_cart_2
rms_length = sites_cart.rms_length() # rms length
rms_difference = sites_cart.rms_difference(sites_cart_2) # rms diff
x = sites_cart.parts()[0] # x values for each coordinate
y = sites_cart.parts()[1] # y values
z = sites_cart.parts()[2] # z values
sel = (x > 10) # all sites where x value is > 10
sel_y = y.select(sel) # selected y values
new_y = y.set_selected(sel,sel_y + 3) # add 3 to selected y values
# Note: sel_y.size() == sel.count(True)
from scitbx.array_family import flex
new_sites_cart = flex.vec3_double(x, new_y, z) # new sites with new y
ncs_d7 = dm.get_ncs_spec("D7.ncs_spec") # reconstruction symmetry file
ncs_d7.display_all() # print out ncs
ncs_d7_model = dm.get_model("D7.pdb") # model with D7 symmetry
ncs_d7_model.search_for_ncs() # find NCS in this model
ncs_spec_object = ncs_d7_model.get_ncs_obj().get_ncs_info_as_spec() # ncs
print (ncs_spec_object.display_all()) # print out summary
mmm = dm.get_map_model_manager(model_file="D7.pdb", # model
map_files="D7.ccp4") #map
build=mmm.model_building() # get a model-building object
build.map_manager().find_map_symmetry(symmetry = "D7") # find symmetry in map
build.map_manager().ncs_object().display_all() # summary
model_no_ncs = build.model().apply_selection_string("chain A") #
print (model_no_ncs)# make sure we got one chain
model_ncs = build.apply_ncs(model = model_no_ncs) # apply ncs to model_no_ncs
print (model_ncs) # now we have 14 chains