1 from __future__
import print_function
2 import pyRMSD.RMSDCalculator
3 from pyRMSD.condensedMatrix
import CondensedMatrix
15 def parse_rmsd_selection(h, selection, resolution=1):
17 for domain_list
in selection.values():
23 for domain
in domain_list:
25 start_res = int(domain[0])
26 end_res = int(domain[1])
28 prot_plus_copy = domain[2]
30 if "." in prot_plus_copy:
31 copy_number = int(prot_plus_copy.split(
".")[1])
32 prot_name = prot_plus_copy.split(
".")[0]
36 prot_name = prot_plus_copy
40 copy_index=copy_number,
41 residue_indexes=range(start_res, end_res+1))
50 def get_pdbs_coordinates(path, idfile_A, idfile_B):
59 with open(idfile_A,
'w+')
as f1:
60 for str_file
in sorted(
61 glob.glob(
"%s/sample_A/*.pdb" % path),
62 key=
lambda x: int(x.split(
'/')[-1].split(
'.')[0])):
63 print(str_file, num, file=f1)
64 models_name.append(str_file)
78 with open(idfile_B,
'w+')
as f2:
79 for str_file
in sorted(
80 glob.glob(
"%s/sample_B/*.pdb" % path),
81 key=
lambda x: int(x.split(
'/')[-1].split(
'.')[0])):
82 print(str_file, num, file=f2)
83 models_name.append(str_file)
94 return np.array(conform), masses, radii, models_name
97 def get_rmfs_coordinates(path, idfile_A, idfile_B,
98 subunit_name=
None, selection=
None, resolution=1):
106 f1 = open(idfile_A,
'w+')
107 f2 = open(idfile_B,
'w+')
111 for sample_name, sample_id_file
in zip([
'A',
'B'], [f1, f2]):
113 for str_file
in sorted(
114 glob.glob(
"%s/sample_%s/*.rmf3" % (path, sample_name)),
115 key=
lambda x: int(x.split(
'/')[-1].split(
'.')[0])):
116 print(str_file, num, file=sample_id_file)
117 models_name.append(str_file)
120 inf = RMF.open_rmf_file_read_only(str_file)
128 molecule=subunit_name)
129 elif selection
is not None:
130 s0 = parse_rmsd_selection(h, selection, resolution)
134 for leaf
in s0.get_selected_particles():
137 pts.append([p.get_coordinates()[i]
for i
in range(3)])
139 if num == 0
and sample_name ==
'A':
141 radii.append(p.get_radius())
155 mol_name +
"_" + str(min(residues_in_bead)) +
"_"
156 + str(max(residues_in_bead)) +
"_"
163 ps_names.append(mol_name +
"_" + residue_in_bead +
"_"
164 + residue_in_bead +
"_"
173 return ps_names, masses, radii, np.array(conform), models_name
176 def parse_symmetric_groups_file(symm_groups_file):
178 member_to_symm_group = {}
179 first_group_member = []
180 curr_particle_index_in_group = []
182 sgf = open(symm_groups_file,
'r')
184 for indx, ln
in enumerate(sgf.readlines()):
186 symm_groups.append([])
188 curr_particle_index_in_group.append(-1)
189 fields = ln.strip().split()
193 member_to_symm_group[fld] = indx
197 first_group_member.append(fields[0])
201 return (symm_groups, member_to_symm_group, curr_particle_index_in_group,
205 def get_rmfs_coordinates_one_rmf(path, rmf_A, rmf_B, subunit_name=None,
206 symm_groups_file=
None, selection=
None,
208 '''Modified RMF coordinates function to work with symmetric copies'''
211 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path, rmf_A))
212 n_models = [rmf_fh.get_number_of_frames()]
213 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path, rmf_B))
214 n_models.append(rmf_fh.get_number_of_frames())
235 molecule=subunit_name)
236 elif selection
is not None:
237 s0 = parse_rmsd_selection(h, selection, resolution)
242 for leaf
in s0.get_selected_particles():
247 conform = np.empty([n_models[0]+n_models[1], pts, 3])
252 (symm_groups, group_member_to_symm_group_map,
253 curr_particle_index_in_group, first_group_member) = \
254 parse_symmetric_groups_file(symm_groups_file)
260 for rmf_file
in [rmf_A, rmf_B]:
262 models_name.append(rmf_file)
264 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path, rmf_file))
267 print(
"Opening RMF file:", rmf_file,
"with",
268 rmf_fh.get_number_of_frames(),
"frames")
270 for f
in range(rmf_fh.get_number_of_frames()):
274 print(
" -- Opening frame", f,
"of",
275 rmf_fh.get_number_of_frames())
285 molecule=subunit_name)
286 elif selection
is not None:
287 s0 = parse_rmsd_selection(h, selection, resolution)
291 particles = s0.get_selected_particles()
294 for i
in range(len(particles)):
299 pxyz = p.get_coordinates()
300 conform[mod_id][i][0] = pxyz[0]
301 conform[mod_id][i][1] = pxyz[1]
302 conform[mod_id][i][2] = pxyz[2]
306 if mod_id == 0
and rmf_file == rmf_A:
308 radii.append(p.get_radius())
319 protein_plus_copy = mol_name+
'.'+str(copy_number)
320 if protein_plus_copy
in group_member_to_symm_group_map:
322 group_index = group_member_to_symm_group_map[
324 curr_particle_index_in_group[group_index] += 1
326 if protein_plus_copy \
327 == first_group_member[group_index]:
328 symm_groups[group_index].append([i])
331 j = curr_particle_index_in_group[group_index] \
332 % len(symm_groups[group_index])
333 symm_groups[group_index][j].append(i)
340 mol_name +
"_" + str(min(residues_in_bead)) +
"_"
341 + str(max(residues_in_bead)) +
"_"
347 mol_name +
"_" + residue_in_bead +
"_" +
348 residue_in_bead +
"_" + str(copy_number))
352 for grp
in symm_groups:
354 print(
"Warning. Symmetry option specified but created "
355 "symmetry group is empty. Cross-check the "
356 "specification of symmetry groups.")
358 return ps_names, masses, radii, conform, symm_groups, models_name, n_models
361 def get_rmsds_matrix(conforms, mode, sup, cores, symm_groups=None):
363 if (mode ==
"cpu_serial" and not sup)
or (mode ==
"cpu_omp" and not sup):
364 calculator_name =
"NOSUP_OMP_CALCULATOR"
366 elif mode ==
"cpu_omp" and sup:
367 calculator_name =
"QCP_OMP_CALCULATOR"
368 print(
"we are using QCP_OMP to compute RMSD")
369 elif mode ==
"cuda" and sup:
370 calculator_name =
"QCP_CUDA_MEM_CALCULATOR"
372 print(
"Wrong values to pyRMSD ! Please Fix")
376 print(
"We have ambiguity.")
377 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(
379 fittingCoordsets=conforms,
380 calcSymmetryGroups=symm_groups,
381 fitSymmetryGroups=symm_groups)
384 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(
385 calculator_name, conforms)
388 if mode ==
"cpu_omp":
389 calculator.setNumberOfOpenMPThreads(int(cores))
391 rmsd = calculator.pairwiseRMSDMatrix()
392 rmsd_matrix = CondensedMatrix(rmsd)
393 inner_data = rmsd_matrix.get_data()
394 np.save(
"Distances_Matrix.data", inner_data)
Select non water and non hydrogen atoms.
A decorator to associate a particle with a part of a protein/DNA/RNA.
atom::Hierarchies create_hierarchies(RMF::FileConstHandle fh, Model *m)
double get_mass(ResidueType c)
Get the mass from the residue type.
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
static bool get_is_setup(Model *m, ParticleIndex pi)
The standard decorator for manipulating molecular structures.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
void load_frame(RMF::FileConstHandle file, RMF::FrameID frame)
Load the given RMF frame into the state of the linked objects.
A decorator for a particle with x,y,z coordinates.
std::string get_molecule_name(Hierarchy h)
A decorator for a residue.
int get_copy_index(Hierarchy h)
Walk up the hierarchy to find the current copy index.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Support for the RMF file format for storing hierarchical molecular data and markup.
A decorator for a particle with x,y,z coordinates and a radius.