1 from __future__
import print_function
2 import pyRMSD.RMSDCalculator
3 from pyRMSD.matrixHandler
import MatrixHandler
4 from pyRMSD.condensedMatrix
import CondensedMatrix
14 def get_pdbs_coordinates(path, idfile_A, idfile_B):
24 with open(idfile_A,
'w+')
as f1:
25 for str_file
in sorted(glob.glob(
"%s/sample_A/*.pdb" % path),
26 key=
lambda x:int(x.split(
'/')[-1].split(
'.')[0])):
27 print(str_file, num, file=f1)
28 models_name.append(str_file)
42 with open(idfile_B,
'w+')
as f2:
43 for str_file
in sorted(glob.glob(
"%s/sample_B/*.pdb" % path),
44 key=
lambda x:int(x.split(
'/')[-1].split(
'.')[0])):
45 print(str_file, num, file=f2)
46 models_name.append(str_file)
57 return np.array(conform), masses, radii, models_name
59 def get_rmfs_coordinates(path, idfile_A, idfile_B, subunit_name):
67 f1=open(idfile_A,
'w+')
68 f2=open(idfile_B,
'w+')
72 for sample_name,sample_id_file
in zip([
'A',
'B'],[f1,f2]):
74 for str_file
in sorted(glob.glob(
"%s/sample_%s/*.rmf3" % (path,sample_name)),key=
lambda x:int(x.split(
'/')[-1].split(
'.')[0])):
75 print(str_file, num, file=sample_id_file)
76 models_name.append(str_file)
79 inf = RMF.open_rmf_file_read_only(str_file)
90 for leaf
in s0.get_selected_particles():
93 pts.append([p.get_coordinates()[i]
for i
in range(3)])
95 if num == 0
and sample_name==
'A':
97 radii.append(p.get_radius())
105 ps_names.append(mol_name+
"_"+str(min(residues_in_bead))+
"_"+str(max(residues_in_bead))+
"_"+str(copy_number))
110 ps_names.append(mol_name+
"_"+residue_in_bead+
"_"+residue_in_bead+
"_"+str(copy_number))
118 return ps_names, masses, radii, np.array(conform), models_name
120 def parse_symmetric_groups_file(symm_groups_file):
123 member_to_symm_group={}
124 first_group_member=[]
125 curr_particle_index_in_group = []
127 sgf = open(symm_groups_file,
'r')
129 for indx,ln
in enumerate(sgf.readlines()):
131 symm_groups.append([])
132 curr_particle_index_in_group.append(-1)
134 fields = ln.strip().split()
137 member_to_symm_group[fld] = indx
139 first_group_member.append(fields[0])
143 return (symm_groups, member_to_symm_group, curr_particle_index_in_group, first_group_member)
145 def get_rmfs_coordinates_one_rmf(path, rmf_A, rmf_B, subunit_name=None, symm_groups_file=None):
147 '''Modified RMF coordinates function to work with symmetric copies'''
150 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path,rmf_A))
151 n_models = [rmf_fh.get_number_of_frames()]
152 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path,rmf_B))
153 n_models.append(rmf_fh.get_number_of_frames())
178 for leaf
in s0.get_selected_particles():
183 conform = np.empty([n_models[0]+n_models[1], pts, 3])
187 (symm_groups, group_member_to_symm_group_map, curr_particle_index_in_group, first_group_member)=parse_symmetric_groups_file(symm_groups_file)
188 else: symm_groups =
None
192 for rmf_file
in [rmf_A, rmf_B]:
194 models_name.append(rmf_file)
196 rmf_fh = RMF.open_rmf_file_read_only(os.path.join(path,rmf_file))
199 print(
"Opening RMF file:", rmf_file,
"with", rmf_fh.get_number_of_frames(),
"frames")
201 for f
in range(rmf_fh.get_number_of_frames()):
205 print(
" -- Opening frame", f,
"of", rmf_fh.get_number_of_frames())
217 particles = s0.get_selected_particles()
221 for i
in range(len(particles)):
225 pxyz = p.get_coordinates()
226 conform[mod_id][i][0] = pxyz[0]
227 conform[mod_id][i][1] = pxyz[1]
228 conform[mod_id][i][2] = pxyz[2]
231 if mod_id == 0
and rmf_file==rmf_A:
233 radii.append(p.get_radius())
241 protein_plus_copy = mol_name+
'.'+str(copy_number)
243 if protein_plus_copy
in group_member_to_symm_group_map:
246 group_index=group_member_to_symm_group_map[protein_plus_copy]
248 curr_particle_index_in_group[group_index] +=1
250 if protein_plus_copy == first_group_member[group_index]:
251 symm_groups[group_index].append([i])
254 j = curr_particle_index_in_group[group_index] % len(symm_groups[group_index])
255 symm_groups[group_index][j].append(i)
259 ps_names.append(mol_name+
"_"+str(min(residues_in_bead))+
"_"+str(max(residues_in_bead))+
"_"+str(copy_number))
262 ps_names.append(mol_name+
"_"+residue_in_bead+
"_"+residue_in_bead+
"_"+str(copy_number))
265 return ps_names, masses, radii, conform, symm_groups, models_name, n_models
267 def get_rmsds_matrix(conforms, mode, sup, cores,symm_groups=None):
268 print(
"Mode:",mode,
"Superposition:",sup,
"Number of cores:",cores)
270 if(mode==
"cpu_serial" and not sup)
or (mode==
"cpu_omp" and not sup):
271 calculator_name =
"NOSUP_OMP_CALCULATOR"
273 elif(mode==
"cpu_omp" and sup):
274 calculator_name =
"QCP_OMP_CALCULATOR"
276 elif(mode==
"cuda" and sup):
277 calculator_name =
"QCP_CUDA_MEM_CALCULATOR"
279 print(
"Wrong values to pyRMSD ! Please Fix")
283 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(calculator_name, fittingCoordsets=conforms,calculationCoordsets=conforms,calcSymmetryGroups=symm_groups)
285 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(calculator_name, conforms)
289 calculator.setNumberOfOpenMPThreads(int(cores))
291 rmsd = calculator.pairwiseRMSDMatrix()
292 rmsd_matrix=CondensedMatrix(rmsd)
293 inner_data = rmsd_matrix.get_data()
294 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.