3 """@namespace IMP.pmi.tools
4 Miscellaneous utilities.
7 from __future__
import print_function
15 from math
import log,pi,sqrt,exp
22 from collections
import defaultdict
24 from collections
import OrderedDict
26 from IMP.pmi._compat_collections
import OrderedDict
29 def _get_system_for_hier(hier):
30 """Given a hierarchy, return the System that created it, or None"""
33 if hier
and not hasattr(hier,
'get_parent'):
40 if hasattr(hier,
'_pmi2_system'):
41 return hier._pmi2_system()
44 for ws
in IMP.pmi.topology.System._all_systems:
46 if s
and s.hier == hier:
49 hier = hier.get_parent()
51 def _all_protocol_outputs(representations, hier):
52 """Iterate over all (ProtocolOutput, State) pairs for the given
53 representations (PMI1) or hier (PMI2)"""
55 system = _get_system_for_hier(hier)
57 for state
in system.states:
58 for p
in state._protocol_output:
61 for p
in representations[0]._protocol_output:
64 def _add_pmi_provenance(p):
65 """Tag the given particle as being created by the current version of PMI."""
69 location=
"https://integrativemodeling.org")
72 def _get_restraint_set_keys():
73 if not hasattr(_get_restraint_set_keys,
'pmi_rs_key'):
74 _get_restraint_set_keys.pmi_rs_key =
IMP.ModelKey(
"PMI restraints")
75 _get_restraint_set_keys.rmf_rs_key =
IMP.ModelKey(
"RMF restraints")
76 return (_get_restraint_set_keys.pmi_rs_key,
77 _get_restraint_set_keys.rmf_rs_key)
79 def _add_restraint_sets(model, mk, mk_rmf):
82 model.add_data(mk, rs)
83 model.add_data(mk_rmf, rs_rmf)
87 """Add a PMI restraint to the model.
88 Since Model.add_restraint() no longer exists (in modern IMP restraints
89 should be added to a ScoringFunction instead) store them instead in
90 a RestraintSet, and keep a reference to it in the Model.
92 If `add_to_rmf` is True, also add the restraint to a separate list
93 of restraints that will be written out to RMF files (by default, most
94 PMI restraints are not)."""
95 mk, mk_rmf = _get_restraint_set_keys()
96 if model.get_has_data(mk):
97 rs = IMP.RestraintSet.get_from(model.get_data(mk))
98 rs_rmf = IMP.RestraintSet.get_from(model.get_data(mk_rmf))
100 rs, rs_rmf = _add_restraint_sets(model, mk, mk_rmf)
101 rs.add_restraint(restraint)
103 rs_rmf.add_restraint(restraint)
106 """Get a RestraintSet containing all PMI restraints added to the model.
107 If `rmf` is True, return only the subset of these restraints that
108 should be written out to RMF files."""
109 mk, mk_rmf = _get_restraint_set_keys()
110 if not model.get_has_data(mk):
111 warnings.warn(
"no restraints added to model yet",
113 _add_restraint_sets(model, mk, mk_rmf)
115 return IMP.RestraintSet.get_from(model.get_data(mk_rmf))
117 return IMP.RestraintSet.get_from(model.get_data(mk))
120 """Collect timing information.
121 Add an instance of this class to outputobjects to get timing information
126 @param isdelta if True (the default) then report the time since the
127 last use of this class; if False, report cumulative time."""
128 self.starttime = time.clock()
130 self.isdelta = isdelta
132 def set_label(self, labelstr):
133 self.label = labelstr
135 def get_output(self):
138 newtime = time.clock()
139 output[
"Stopwatch_" + self.label +
"_delta_seconds"] \
140 = str(newtime - self.starttime)
141 self.starttime = newtime
143 output[
"Stopwatch_" + self.label +
"_elapsed_seconds"] \
144 = str(time.clock() - self.starttime)
148 class SetupNuisance(object):
150 def __init__(self, m, initialvalue, minvalue, maxvalue, isoptimized=True):
154 nuisance.set_lower(minvalue)
156 nuisance.set_upper(maxvalue)
159 nuisance.set_is_optimized(nuisance.get_nuisance_key(), isoptimized)
160 self.nuisance = nuisance
162 def get_particle(self):
166 class SetupWeight(object):
168 def __init__(self, m, isoptimized=True):
171 self.weight.set_weights_are_optimized(
True)
173 def get_particle(self):
177 class SetupSurface(object):
179 def __init__(self, m, center, normal, isoptimized=True):
182 self.surface.set_coordinates_are_optimized(isoptimized)
183 self.surface.set_normal_is_optimized(isoptimized)
185 def get_particle(self):
189 class ParticleToSampleList(object):
193 self.dictionary_particle_type = {}
194 self.dictionary_particle_transformation = {}
195 self.dictionary_particle_name = {}
202 particle_transformation,
204 if not particle_type
in [
"Rigid_Bodies",
"Floppy_Bodies",
"Nuisances",
"X_coord",
"Weights",
"Surfaces"]:
205 raise TypeError(
"not the right particle type")
207 self.dictionary_particle_type[particle] = particle_type
208 if particle_type ==
"Rigid_Bodies":
209 if (isinstance(particle_transformation, tuple)
210 and len(particle_transformation) == 2
211 and all(isinstance(x, float)
212 for x
in particle_transformation)):
213 self.dictionary_particle_transformation[
214 particle] = particle_transformation
215 self.dictionary_particle_name[particle] = name
217 raise TypeError(
"ParticleToSampleList: not the right transformation format for Rigid_Bodies, should be a tuple of floats")
218 elif particle_type ==
"Surfaces":
219 if (isinstance(particle_transformation, tuple)
220 and len(particle_transformation) == 3
221 and all(isinstance(x, float)
222 for x
in particle_transformation)):
223 self.dictionary_particle_transformation[
224 particle] = particle_transformation
225 self.dictionary_particle_name[particle] = name
227 raise TypeError(
"ParticleToSampleList: not the right transformation format for Surfaces, should be a tuple of floats")
229 if isinstance(particle_transformation, float):
230 self.dictionary_particle_transformation[
231 particle] = particle_transformation
232 self.dictionary_particle_name[particle] = name
234 raise TypeError(
"ParticleToSampleList: not the right transformation format, should be a float")
236 def get_particles_to_sample(self):
238 for particle
in self.dictionary_particle_type:
239 key = self.dictionary_particle_type[
240 particle] +
"ParticleToSampleList_" + self.dictionary_particle_name[particle] +
"_" + self.label
243 self.dictionary_particle_transformation[particle])
250 number_of_cross_links=10,
251 ambiguity_probability=0.1,
252 confidence_score_range=[0,100],
253 avoid_same_particles=
False):
254 '''Return a random cross-link dataset as a string.
255 Every line is a residue pair, together with UniqueIdentifier
258 residue_pairs=get_random_residue_pairs(representation, resolution, number_of_cross_links, avoid_same_particles=avoid_same_particles)
261 cmin=float(min(confidence_score_range))
262 cmax=float(max(confidence_score_range))
266 for (name1, r1, name2, r2)
in residue_pairs:
267 if random.random() > ambiguity_probability:
269 score=random.random()*(cmax-cmin)+cmin
270 dataset+=str(name1)+
" "+str(name2)+
" "+str(r1)+
" "+str(r2)+
" "+str(score)+
" "+str(unique_identifier)+
"\n"
277 def get_cross_link_data(directory, filename, dist, omega, sigma,
278 don=
None, doff=
None, prior=0, type_of_profile=
"gofr"):
280 (distmin, distmax, ndist) = dist
281 (omegamin, omegamax, nomega) = omega
282 (sigmamin, sigmamax, nsigma) = sigma
285 with open(filen)
as xlpot:
286 dictionary = ast.literal_eval(xlpot.readline())
288 xpot = dictionary[directory][filename][
"distance"]
289 pot = dictionary[directory][filename][type_of_profile]
291 dist_grid =
get_grid(distmin, distmax, ndist,
False)
292 omega_grid = get_log_grid(omegamin, omegamax, nomega)
293 sigma_grid = get_log_grid(sigmamin, sigmamax, nsigma)
295 if not don
is None and not doff
is None:
314 def get_grid(gmin, gmax, ngrid, boundaries):
316 dx = (gmax - gmin) / float(ngrid)
317 for i
in range(0, ngrid + 1):
318 if(
not boundaries
and i == 0):
320 if(
not boundaries
and i == ngrid):
322 grid.append(gmin + float(i) * dx)
328 def get_log_grid(gmin, gmax, ngrid):
330 for i
in range(0, ngrid + 1):
331 grid.append(gmin * exp(float(i) / ngrid * log(gmax / gmin)))
339 example '"{ID_Score}" > 28 AND "{Sample}" ==
340 "%10_1%" OR ":Sample}" == "%10_2%" OR ":Sample}"
341 == "%10_3%" OR ":Sample}" == "%8_1%" OR ":Sample}" == "%8_2%"'
344 import pyparsing
as pp
346 operator = pp.Regex(
">=|<=|!=|>|<|==|in").setName(
"operator")
347 value = pp.QuotedString(
349 r"[+-]?\d+(:?\.\d*)?(:?[eE][+-]?\d+)?")
350 identifier = pp.Word(pp.alphas, pp.alphanums +
"_")
351 comparison_term = identifier | value
352 condition = pp.Group(comparison_term + operator + comparison_term)
354 expr = pp.operatorPrecedence(condition, [
355 (
"OR", 2, pp.opAssoc.LEFT, ),
356 (
"AND", 2, pp.opAssoc.LEFT, ),
359 parsedstring = str(expr.parseString(inputstring)) \
365 .replace(
"{",
"float(entry['") \
366 .replace(
"}",
"'])") \
367 .replace(
":",
"str(entry['") \
368 .replace(
"}",
"'])") \
369 .replace(
"AND",
"and") \
374 def open_file_or_inline_text(filename):
376 fl = open(filename,
"r")
378 fl = filename.split(
"\n")
381 def get_ids_from_fasta_file(fastafile):
383 with open(fastafile)
as ff:
392 this function works with plain hierarchies, as read from the pdb,
393 no multi-scale hierarchies
400 atom_type=IMP.atom.AT_CA)
408 print(
"get_closest_residue_position: exiting while loop without result")
410 p = sel.get_selected_particles()
415 print(
"get_closest_residue_position: got NO residues for hierarchy %s and residue %i" % (hier, resindex))
416 raise Exception(
"get_closest_residue_position: got NO residues for hierarchy %s and residue %i" % (
419 raise ValueError(
"got multiple residues for hierarchy %s and residue %i; the list of particles is %s" % (hier, resindex, str([pp.get_name()
for pp
in p])))
423 Get the particle of the terminal residue at the GIVEN resolution
424 (NOTE: not the closest resolution!).
425 To get the terminal residue at the closest resolution use:
426 particles=IMP.pmi.tools.select_by_tuple(representation,molecule_name)
427 particles[0] and particles[-1] will be the first and last particles
428 corresponding to the two termini.
429 It is needed for instance to determine the last residue of a pdb.
430 @param hier hierarchy containing the terminal residue
431 @param terminus either 'N' or 'C'
432 @param resolution resolution to use.
438 resolution=resolution,
445 if termresidue
is None:
446 termresidue = max(residues)
448 elif max(residues) >= termresidue:
449 termresidue = max(residues)
451 elif terminus ==
"N":
452 if termresidue
is None:
453 termresidue = min(residues)
455 elif min(residues) <= termresidue:
456 termresidue = min(residues)
459 raise ValueError(
"terminus argument should be either N or C")
464 """Get XYZ coordinates of the terminal residue at the GIVEN resolution"""
470 Return the residue index gaps and contiguous segments in the hierarchy.
472 @param hierarchy hierarchy to examine
473 @param start first residue index
474 @param end last residue index
476 @return A list of lists of the form
477 [[1,100,"cont"],[101,120,"gap"],[121,200,"cont"]]
480 for n, rindex
in enumerate(range(start, end + 1)):
482 atom_type=IMP.atom.AT_CA)
484 if len(sel.get_selected_particles()) == 0:
488 rindexcont = start - 1
489 if rindexgap == rindex - 1:
495 gaps.append([rindex, rindex,
"gap"])
501 rindexgap = start - 1
503 if rindexcont == rindex - 1:
510 gaps.append([rindex, rindex,
"cont"])
521 def set_map_element(self, xvalue, yvalue):
522 self.map[xvalue] = yvalue
524 def get_map_element(self, invalue):
525 if isinstance(invalue, float):
529 dist = (invalue - x) * (invalue - x)
538 return self.map[minx]
539 elif isinstance(invalue, str):
540 return self.map[invalue]
542 raise TypeError(
"wrong type for map")
548 selection_arguments=
None,
550 name_is_ambiguous=
False,
554 representation_type=
None):
556 this function uses representation=SimplifiedModel
557 it returns the corresponding selected particles
558 representation_type="Beads", "Res:X", "Densities", "Representation", "Molecule"
561 if resolution
is None:
563 resolution_particles =
None
564 hierarchies_particles =
None
565 names_particles =
None
566 residue_range_particles =
None
567 residue_particles =
None
568 representation_type_particles =
None
570 if not resolution
is None:
571 resolution_particles = []
572 hs = representation.get_hierarchies_at_given_resolution(resolution)
576 if not hierarchies
is None:
577 hierarchies_particles = []
578 for h
in hierarchies:
583 if name_is_ambiguous:
584 for namekey
in representation.hier_dict:
587 representation.hier_dict[namekey])
588 elif name
in representation.hier_dict:
591 print(
"select: component %s is not there" % name)
593 if not first_residue
is None and not last_residue
is None:
595 residue_indexes=range(first_residue, last_residue + 1))
597 for p
in sel.get_selected_particles()]
599 if not residue
is None:
602 for p
in sel.get_selected_particles()]
604 if not representation_type
is None:
605 representation_type_particles = []
606 if representation_type ==
"Molecule":
607 for name
in representation.hier_representation:
608 for repr_type
in representation.hier_representation[name]:
609 if repr_type ==
"Beads" or "Res:" in repr_type:
610 h = representation.hier_representation[name][repr_type]
613 elif representation_type ==
"PDB":
614 for name
in representation.hier_representation:
615 for repr_type
in representation.hier_representation[name]:
616 if repr_type ==
"Res:" in repr_type:
617 h = representation.hier_representation[name][repr_type]
621 for name
in representation.hier_representation:
622 h = representation.hier_representation[
627 selections = [hierarchies_particles, names_particles,
628 residue_range_particles, residue_particles, representation_type_particles]
630 if resolution
is None:
631 selected_particles = set(allparticles)
633 selected_particles = set(resolution_particles)
637 selected_particles = (set(s) & selected_particles)
639 return list(selected_particles)
646 name_is_ambiguous=
False):
647 if isinstance(tupleselection, tuple)
and len(tupleselection) == 3:
649 name=tupleselection[2],
650 first_residue=tupleselection[0],
651 last_residue=tupleselection[1],
652 name_is_ambiguous=name_is_ambiguous)
653 elif isinstance(tupleselection, str):
656 name_is_ambiguous=name_is_ambiguous)
658 raise ValueError(
'you passed something bad to select_by_tuple()')
660 particles = IMP.pmi.tools.sort_by_residues(particles)
665 """New tuple format: molname OR (start,stop,molname,copynum,statenum)
666 Copy and state are optional. Can also use 'None' for them which will get all.
667 You can also pass -1 for stop which will go to the end.
668 Returns the particles
671 kwds[
'resolution'] = resolution
672 if isinstance(tuple_selection, str):
673 kwds[
'molecule'] = tuple_selection
674 elif isinstance(tuple_selection, tuple):
675 rbegin = tuple_selection[0]
676 rend = tuple_selection[1]
677 kwds[
'molecule'] = tuple_selection[2]
679 copynum = tuple_selection[3]
680 if copynum
is not None:
681 kwds[
'copy_index'] = copynum
685 statenum = tuple_selection[4]
686 if statenum
is not None:
687 kwds[
'state_index'] = statenum
694 residue_indexes=range(1,rbegin),
696 return s.get_selected_particles()
698 kwds[
'residue_indexes'] = range(rbegin,rend+1)
700 return s.get_selected_particles()
704 def get_db_from_csv(csvfilename):
707 with open(csvfilename)
as fh:
708 csvr = csv.DictReader(fh)
715 """Store the representations for a system."""
720 self.root_hierarchy_dict = {}
721 self.preroot_fragment_hierarchy_dict = {}
722 self.particle_to_name = {}
725 def add_name(self, name):
726 if name
not in self.db:
729 def add_residue_number(self, name, resn):
732 if resn
not in self.db[name]:
733 self.db[name][resn] = {}
735 def add_resolution(self, name, resn, resolution):
737 resolution = float(resolution)
739 self.add_residue_number(name, resn)
740 if resolution
not in self.db[name][resn]:
741 self.db[name][resn][resolution] = []
745 resolution = float(resolution)
747 self.add_residue_number(name, resn)
748 self.add_resolution(name, resn, resolution)
749 self.db[name][resn][resolution] += particles
751 (rh, prf) = self.get_root_hierarchy(p)
752 self.root_hierarchy_dict[p] = rh
753 self.preroot_fragment_hierarchy_dict[p] = prf
754 self.particle_to_name[p] = name
755 if self.model
is None:
756 self.model = particles[0].get_model()
762 names = list(self.db.keys())
768 resolution = float(resolution)
769 return self.db[name][resn][resolution]
771 def get_particles_at_closest_resolution(self, name, resn, resolution):
773 resolution = float(resolution)
774 closestres = min(self.get_residue_resolutions(name, resn),
775 key=
lambda x: abs(float(x) - float(resolution)))
776 return self.get_particles(name, resn, closestres)
778 def get_residue_resolutions(self, name, resn):
780 resolutions = list(self.db[name][resn].keys())
784 def get_molecule_resolutions(self, name):
786 for resn
in self.db[name]:
787 resolutions.update(list(self.db[name][resn].keys()))
791 def get_residue_numbers(self, name):
792 residue_numbers = list(self.db[name].keys())
793 residue_numbers.sort()
794 return residue_numbers
796 def get_particles_by_resolution(self, name, resolution):
797 resolution = float(resolution)
799 for resn
in self.get_residue_numbers(name):
800 result = self.get_particles_at_closest_resolution(
804 pstemp = [p
for p
in result
if p
not in particles]
808 def get_all_particles_by_resolution(self, resolution):
809 resolution = float(resolution)
811 for name
in self.get_names():
812 particles += self.get_particles_by_resolution(name, resolution)
815 def get_root_hierarchy(self, particle):
816 prerootfragment = particle
826 prerootfragment = particle
832 def get_all_root_hierarchies_by_resolution(self, resolution):
834 resolution = float(resolution)
835 particles = self.get_all_particles_by_resolution(resolution)
837 rh = self.root_hierarchy_dict[p]
838 if rh
not in hierarchies:
842 def get_preroot_fragments_by_resolution(self, name, resolution):
844 resolution = float(resolution)
845 particles = self.get_particles_by_resolution(name, resolution)
847 fr = self.preroot_fragment_hierarchy_dict[p]
848 if fr
not in fragments:
852 def show(self, name):
854 for resn
in self.get_residue_numbers(name):
856 for resolution
in self.get_residue_resolutions(name, resn):
857 print(
"----", resolution)
858 for p
in self.get_particles(name, resn, resolution):
859 print(
"--------", p.get_name())
863 '''Return the component name provided a particle and a list of names'''
865 protname = root.get_name()
867 while not protname
in list_of_names:
868 root0 = root.get_parent()
871 protname = root0.get_name()
876 if "Beads" in protname:
879 return (protname, is_a_bead)
884 Retrieve the residue indexes for the given particle.
886 The particle must be an instance of Fragment,Residue, Atom or Molecule
887 or else returns an empty list
898 resind_tmp=IMP.pmi.tools.OrderedSet()
904 resind=list(resind_tmp)
910 def sort_by_residues(particles):
913 sorted_particles_residues = sorted(
915 key=
lambda tup: tup[1])
916 particles = [p[0]
for p
in sorted_particles_residues]
925 """Synchronize data over a parallel run"""
926 from mpi4py
import MPI
927 comm = MPI.COMM_WORLD
928 rank = comm.Get_rank()
929 number_of_processes = comm.size
932 comm.send(data, dest=0, tag=11)
935 for i
in range(1, number_of_processes):
936 data_tmp = comm.recv(source=i, tag=11)
937 if isinstance(data, list):
939 elif isinstance(data, dict):
940 data.update(data_tmp)
942 raise TypeError(
"data not supported, use list or dictionaries")
944 for i
in range(1, number_of_processes):
945 comm.send(data, dest=i, tag=11)
948 data = comm.recv(source=0, tag=11)
957 Yield all sublists of length >= lmin and <= lmax
965 for j
in range(i + 1, n):
966 if len(l[i:j]) <= lmax
and len(l[i:j]) >= lmin:
971 return [item
for sublist
in l
for item
in sublist]
975 """ Yield successive length-sized chunks from a list.
977 for i
in range(0, len(list), length):
978 yield list[i:i + length]
981 def chunk_list_into_segments(seq, num):
983 avg = len(seq) / float(num)
987 while last < len(seq):
988 out.append(seq[int(last):int(last + avg)])
996 ''' This class stores integers
997 in ordered compact lists eg:
999 the methods help splitting and merging the internal lists
1001 s=Segments([1,2,3]) is [[1,2,3]]
1002 s.add(4) is [[1,2,3,4]] (add right)
1003 s.add(3) is [[1,2,3,4]] (item already existing)
1004 s.add(7) is [[1,2,3,4],[7]] (new list)
1005 s.add([8,9]) is [[1,2,3,4],[7,8,9]] (add item right)
1006 s.add([5,6]) is [[1,2,3,4,5,6,7,8,9]] (merge)
1007 s.remove(3) is [[1,2],[4,5,6,7,8,9]] (split)
1012 '''index can be a integer or a list of integers '''
1013 if isinstance(index, int):
1015 elif isinstance(index, list):
1016 self.segs=[[index[0]]]
1020 raise TypeError(
"index must be an int or list of ints")
1023 '''index can be a integer or a list of integers '''
1024 if isinstance(index, int):
1027 for n,s
in enumerate(self.segs):
1035 if mergeright
is None and mergeleft
is None:
1036 self.segs.append([index])
1037 if not mergeright
is None and mergeleft
is None:
1038 self.segs[mergeright].append(index)
1039 if not mergeleft
is None and mergeright
is None:
1040 self.segs[mergeleft]=[index]+self.segs[mergeleft]
1041 if not mergeleft
is None and not mergeright
is None:
1042 self.segs[mergeright]=self.segs[mergeright]+[index]+self.segs[mergeleft]
1043 del self.segs[mergeleft]
1045 for n
in range(len(self.segs)):
1048 self.segs.sort(key=
lambda tup: tup[0])
1050 elif isinstance(index, list):
1054 raise TypeError(
"index must be an int or list of ints")
1057 '''index can be a integer'''
1058 for n,s
in enumerate(self.segs):
1065 i=self.segs[n].index(index)
1067 self.segs.append(s[i+1:])
1068 for n
in range(len(self.segs)):
1070 if len(self.segs[n])==0:
1072 self.segs.sort(key=
lambda tup: tup[0])
1075 ''' Returns a flatten list '''
1076 return [item
for sublist
in self.segs
for item
in sublist]
1080 for seg
in self.segs:
1081 ret_tmp+=str(seg[0])+
"-"+str(seg[-1])+
","
1082 ret=ret_tmp[:-1]+
"]"
1089 def normal_density_function(expected_value, sigma, x):
1091 1 / math.sqrt(2 * math.pi) / sigma *
1092 math.exp(-(x - expected_value) ** 2 / 2 / sigma / sigma)
1096 def log_normal_density_function(expected_value, sigma, x):
1098 1 / math.sqrt(2 * math.pi) / sigma / x *
1099 math.exp(-(math.log(x / expected_value) ** 2 / 2 / sigma / sigma))
1103 def get_random_residue_pairs(representation, resolution,
1106 avoid_same_particles=
False,
1111 names=list(representation.hier_dict.keys())
1114 prot = representation.hier_dict[name]
1115 particles +=
select(representation,name=name,resolution=resolution)
1116 random_residue_pairs = []
1117 while len(random_residue_pairs)<=number:
1118 p1 = random.choice(particles)
1119 p2 = random.choice(particles)
1120 if max_distance
is not None and \
1125 if r1==r2
and avoid_same_particles:
continue
1126 name1 = representation.get_prot_name_from_particle(p1)
1127 name2 = representation.get_prot_name_from_particle(p2)
1128 random_residue_pairs.append((name1, r1, name2, r2))
1130 return random_residue_pairs
1132 def print_multicolumn(list_of_strings, ncolumns=2, truncate=40):
1138 for i
in range(len(l) % cols):
1141 split = [l[i:i + len(l) / cols]
for i
in range(0, len(l), len(l) / cols)]
1142 for row
in zip(*split):
1143 print(
"".join(str.ljust(i, truncate)
for i
in row))
1146 '''Change color code to hexadecimal to rgb'''
1148 self._NUMERALS =
'0123456789abcdefABCDEF'
1149 self._HEXDEC = dict((v, int(v, 16))
for v
in (x+y
for x
in self._NUMERALS
for y
in self._NUMERALS))
1150 self.LOWERCASE, self.UPPERCASE =
'x',
'X'
1152 def rgb(self,triplet):
1153 return float(self._HEXDEC[triplet[0:2]]), float(self._HEXDEC[triplet[2:4]]), float(self._HEXDEC[triplet[4:6]])
1155 def triplet(self,rgb, lettercase=None):
1156 if lettercase
is None: lettercase=self.LOWERCASE
1157 return format(rgb[0]<<16 | rgb[1]<<8 | rgb[2],
'06'+lettercase)
1161 class OrderedSet(collections.MutableSet):
1163 def __init__(self, iterable=None):
1165 end += [
None, end, end]
1167 if iterable
is not None:
1171 return len(self.map)
1173 def __contains__(self, key):
1174 return key
in self.map
1177 if key
not in self.map:
1180 curr[2] = end[1] = self.map[key] = [key, curr, end]
1182 def discard(self, key):
1184 key, prev, next = self.map.pop(key)
1191 while curr
is not end:
1195 def __reversed__(self):
1198 while curr
is not end:
1202 def pop(self, last=True):
1204 raise KeyError(
'set is empty')
1206 key = self.end[1][0]
1208 key = self.end[2][0]
1214 return '%s()' % (self.__class__.__name__,)
1215 return '%s(%r)' % (self.__class__.__name__, list(self))
1217 def __eq__(self, other):
1218 if isinstance(other, OrderedSet):
1219 return len(self) == len(other)
and list(self) == list(other)
1220 return set(self) == set(other)
1224 """Store objects in order they were added, but with default type.
1225 Source: http://stackoverflow.com/a/4127426/2608793
1227 def __init__(self, *args, **kwargs):
1229 self.default_factory =
None
1231 if not (args[0]
is None or callable(args[0])):
1232 raise TypeError(
'first argument must be callable or None')
1233 self.default_factory = args[0]
1235 super(OrderedDefaultDict, self).__init__(*args, **kwargs)
1237 def __missing__ (self, key):
1238 if self.default_factory
is None:
1240 self[key] = default = self.default_factory()
1243 def __reduce__(self):
1244 args = (self.default_factory,)
if self.default_factory
else ()
1245 if sys.version_info[0] >= 3:
1246 return self.__class__, args,
None,
None, self.items()
1248 return self.__class__, args,
None,
None, self.iteritems()
1254 """Extract frame from RMF file and fill coordinates. Must be identical topology.
1255 @param hier The (System) hierarchy to fill (e.g. after you've built it)
1256 @param rmf_fn The file to extract from
1257 @param frame_num The frame number to extract
1259 rh = RMF.open_rmf_file_read_only(rmf_fn)
1267 selection_tuple=
None,
1268 warn_about_slices=
True):
1269 """Adapt things for PMI (degrees of freedom, restraints, ...)
1270 Returns list of list of hierarchies, separated into Molecules if possible.
1271 The input can be a list, or a list of lists (iterable of ^1 or iterable of ^2)
1272 (iterable of ^2) Hierarchy -> returns input as list of list of hierarchies,
1273 only one entry, not grouped by molecules.
1274 (iterable of ^2) PMI::System/State/Molecule/TempResidue ->
1275 returns residue hierarchies, grouped in molecules, at requested resolution
1276 @param stuff Can be one of the following inputs:
1277 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set (of list/set) of them.
1278 Must be uniform input, however. No mixing object types.
1279 @param pmi_resolution For selecting, only does it if you pass PMI objects. Set it to "all"
1280 if you want all resolutions!
1281 @param flatten Set to True if you just want all hierarchies in one list.
1282 @param warn_about_slices Print a warning if you are requesting only part
1283 of a bead. Sometimes you just don't care!
1284 @note since this relies on IMP::atom::Selection, this will not return
1285 any objects if they weren't built! But there should be no problem
1286 if you request unbuilt residues - they should be ignored.
1292 if hasattr(stuff,
'__iter__'):
1298 if all(hasattr(el,
'__iter__')
for el
in thelist):
1299 thelist = [i
for sublist
in thelist
for i
in sublist]
1300 elif any(hasattr(el,
'__iter__')
for el
in thelist):
1301 raise Exception(
'input_adaptor: input_object must be a list or a list of lists')
1310 except (NotImplementedError, TypeError):
1321 if is_system
or is_state
or is_molecule
or is_temp_residue:
1326 for system
in stuff:
1327 for state
in system.get_states():
1328 mdict = state.get_molecules()
1329 for molname
in mdict:
1330 for copy
in mdict[molname]:
1331 indexes_per_mol[copy] += [r.get_index()
for r
in copy.get_residues()]
1334 mdict = state.get_molecules()
1335 for molname
in mdict:
1336 for copy
in mdict[molname]:
1337 indexes_per_mol[copy] += [r.get_index()
for r
in copy.get_residues()]
1339 for molecule
in stuff:
1340 indexes_per_mol[molecule] += [r.get_index()
for r
in molecule.get_residues()]
1342 for tempres
in stuff:
1343 indexes_per_mol[tempres.get_molecule()].append(tempres.get_index())
1344 for mol
in indexes_per_mol:
1345 if pmi_resolution==
'all':
1349 residue_indexes=indexes_per_mol[mol])
1352 resolution=pmi_resolution,
1353 residue_indexes=indexes_per_mol[mol])
1354 ps = sel.get_selected_particles()
1357 if warn_about_slices:
1358 rset = set(indexes_per_mol[mol])
1362 if not fset <= rset:
1368 resbreak = maxf
if minf==minset
else minset-1
1370 'You are trying to select only part of the '
1371 'bead %s:%i-%i. The residues you requested '
1372 'are %i-%i. You can fix this by: '
1373 '1) requesting the whole bead/none of it; or'
1374 '2) break the bead up by passing '
1375 'bead_extra_breaks=[\'%i\'] in '
1376 'molecule.add_representation()'
1377 %(mol.get_name(), minset, maxset, minf, maxf,
1383 if pmi_resolution==
'all':
1391 hier_list = [hier_list]
1393 raise Exception(
'input_adaptor: you passed something of wrong type or a list with mixed types')
1395 if flatten
and pmi_input:
1396 return [h
for sublist
in hier_list
for h
in sublist]
1402 """Returns sequence-sorted segments array, each containing the first particle
1403 the last particle and the first residue index."""
1405 from operator
import itemgetter
1408 raise ValueError(
"only pass stuff from one Molecule, please")
1424 segs.append((start, end, startres))
1425 return sorted(segs, key=itemgetter(2))
1428 """Decorate the sequence-consecutive particles from a PMI2 molecule with a bond,
1429 so that they appear connected in the rmf file"""
1431 for x
in range(len(SortedSegments) - 1):
1433 last = SortedSegments[x][1]
1434 first = SortedSegments[x + 1][0]
1436 p1 = last.get_particle()
1437 p2 = first.get_particle()
1450 """This class converts three to one letter codes, and return X for any unknown codes"""
1451 def __init__(self,is_nucleic=False):
1454 threetoone = {
'ALA':
'A',
'ARG':
'R', 'ASN': 'N', 'ASP': 'D',
1455 'CYS':
'C',
'GLU':
'E',
'GLN':
'Q',
'GLY':
'G',
1456 'HIS':
'H',
'ILE':
'I',
'LEU':
'L',
'LYS':
'K',
1457 'MET':
'M',
'PHE':
'F',
'PRO':
'P',
'SER':
'S',
1458 'THR':
'T',
'TRP':
'W',
'TYR':
'Y',
'VAL':
'V',
'UNK':
'X'}
1460 threetoone = {
'ADE':
'A',
'URA':
'U', 'CYT': 'C', 'GUA': 'G',
1461 'THY':
'T',
'UNK':
'X'}
1463 defaultdict.__init__(self,
lambda:
"X", threetoone)
1468 def get_residue_type_from_one_letter_code(code,is_nucleic=False):
1471 for k
in threetoone:
1472 one_to_three[threetoone[k]] = k
1477 """ Just get the leaves from a list of hierarchies """
1478 lvs = list(itertools.chain.from_iterable(
IMP.atom.get_leaves(item)
for item
in list_of_hs))
1485 """Perform selection using the usual keywords but return ALL resolutions (BEADS and GAUSSIANS).
1486 Returns in flat list!
1491 if hier
is not None:
1494 warnings.warn(
"You passed nothing to select_at_all_resolutions()",
1502 raise Exception(
'select_at_all_resolutions: you have to pass an IMP Hierarchy')
1504 raise Exception(
'select_at_all_resolutions: you have to pass an IMP Hierarchy')
1505 if 'resolution' in kwargs
or 'representation_type' in kwargs:
1506 raise Exception(
"don't pass resolution or representation_type to this function")
1508 representation_type=IMP.atom.BALLS,**kwargs)
1510 representation_type=IMP.atom.DENSITIES,**kwargs)
1511 ret |= OrderedSet(selB.get_selected_particles())
1512 ret |= OrderedSet(selD.get_selected_particles())
1521 """Utility to retrieve particles from a hierarchy within a
1522 zone around a set of ps.
1523 @param hier The hierarchy in which to look for neighbors
1524 @param target_ps The particles for zoning
1525 @param sel_zone The maximum distance
1526 @param entire_residues If True, will grab entire residues
1527 @param exclude_backbone If True, will only return sidechain particles
1531 backbone_types=[
'C',
'N',
'CB',
'O']
1532 if exclude_backbone:
1534 for n
in backbone_types])
1535 test_ps = test_sel.get_selected_particles()
1536 nn = IMP.algebra.NearestNeighbor3D([
IMP.core.XYZ(p).get_coordinates()
1539 for target
in target_ps:
1540 zone|=set(nn.get_in_ball(
IMP.core.XYZ(target).get_coordinates(),sel_zone))
1541 zone_ps = [test_ps[z]
for z
in zone]
1546 zone_ps = [h.get_particle()
for h
in final_ps]
1551 """Returns unique objects in original order"""
1555 if not hasattr(hiers,
'__iter__'):
1562 rbs_ordered.append(rb)
1567 rbs_ordered.append(rb)
1571 return rbs_ordered,beads
1574 "This function returns the parent molecule hierarchies of given objects"
1575 stuff=
input_adaptor(input_objects, pmi_resolution=
'all',flatten=
True)
1580 while not (is_molecule
or is_root):
1581 root=IMP.atom.get_root(h)
1588 return list(molecules)
1590 def get_molecules_dictionary(input_objects):
1591 moldict=defaultdict(list)
1594 moldict[name].append(mol)
1600 def get_molecules_dictionary_by_copy(input_objects):
1601 moldict=defaultdict(dict)
1605 moldict[name][c]=mol
1608 def get_selections_dictionary(input_objects):
1609 moldict=IMP.pmi.tools.get_molecules_dictionary(input_objects)
1610 seldict=defaultdict(list)
1611 for name, mols
in moldict.items():
1617 """Given a list of PMI objects, returns all density hierarchies within
1618 these objects. The output of this function can be inputted into
1619 things such as EM restraints. This function is intended to gather density particles
1620 appended to molecules (and not other hierarchies which might have been appended to the root node directly).
1627 densities+=
IMP.atom.Selection(i,representation_type=IMP.atom.DENSITIES).get_selected_particles()
1631 max_translation=300., max_rotation=2.0 * pi,
1632 avoidcollision_rb=
True, avoidcollision_fb=
False,
1633 cutoff=10.0, niterations=100,
1635 excluded_rigid_bodies=[],
1636 hierarchies_excluded_from_collision=[],
1637 hierarchies_included_in_collision=[],
1639 return_debug=
False):
1640 """Shuffle particles. Used to restart the optimization.
1641 The configuration of the system is initialized by placing each
1642 rigid body and each bead randomly in a box. If `bounding_box` is
1643 specified, the particles are placed inside this box; otherwise, each
1644 particle is displaced by up to max_translation angstroms, and randomly
1645 rotated. Effort is made to place particles far enough from each other to
1646 prevent any steric clashes.
1647 @param objects Can be one of the following inputs:
1648 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set of them
1649 @param max_translation Max translation (rbs and flexible beads)
1650 @param max_rotation Max rotation (rbs only)
1651 @param avoidcollision_rb check if the particle/rigid body was
1652 placed close to another particle; uses the optional
1653 arguments cutoff and niterations
1654 @param avoidcollision_fb Advanced. Generally you want this False because it's hard to shuffle beads.
1655 @param cutoff Distance less than this is a collision
1656 @param niterations How many times to try avoiding collision
1657 @param bounding_box Only shuffle particles within this box. Defined by ((x1,y1,z1),(x2,y2,z2)).
1658 @param excluded_rigid_bodies Don't shuffle these rigid body objects
1659 @param hierarchies_excluded_from_collision Don't count collision with these bodies
1660 @param hierarchies_included_in_collision Hierarchies that are not shuffled, but should be included in collision calculation (for fixed regions)
1661 @param verbose Give more output
1662 @note Best to only call this function after you've set up degrees of freedom
1663 For debugging purposes, returns: <shuffled indexes>, <collision avoided indexes>
1668 pmi_resolution=
'all',
1671 if len(rigid_bodies)>0:
1672 mdl = rigid_bodies[0].get_model()
1673 elif len(flexible_beads)>0:
1674 mdl = flexible_beads[0].get_model()
1676 raise Exception(
"Could not find any particles in the hierarchy")
1677 if len(rigid_bodies) == 0:
1678 print(
"shuffle_configuration: rigid bodies were not initialized")
1682 gcpf.set_distance(cutoff)
1686 pmi_resolution=
'all',
1690 pmi_resolution=
'all',
1693 collision_excluded_idxs = set([l.get_particle().
get_index()
for h
in collision_excluded_hierarchies \
1696 collision_included_idxs = set([l.get_particle().
get_index()
for h
in collision_included_hierarchies \
1703 all_idxs.append(p.get_particle_index())
1705 collision_excluded_idxs.add(p.get_particle_index())
1707 if bounding_box
is not None:
1708 ((x1, y1, z1), (x2, y2, z2)) = bounding_box
1713 all_idxs = set(all_idxs) | collision_included_idxs
1714 all_idxs = all_idxs - collision_excluded_idxs
1716 print(
'shuffling', len(rigid_bodies),
'rigid bodies')
1717 for rb
in rigid_bodies:
1718 if rb
not in excluded_rigid_bodies:
1720 if avoidcollision_rb:
1721 rb_idxs = set(rb.get_member_particle_indexes()) - \
1722 collision_excluded_idxs
1723 other_idxs = all_idxs - rb_idxs
1729 while niter < niterations:
1730 rbxyz = (rb.get_x(), rb.get_y(), rb.get_z())
1750 debug.append([rb, other_idxs
if avoidcollision_rb
else set()])
1754 if avoidcollision_rb:
1756 npairs = len(gcpf.get_close_pairs(mdl,
1765 print(
"shuffle_configuration: rigid body placed close to other %d particles, trying again..." % npairs)
1766 print(
"shuffle_configuration: rigid body name: " + rb.get_name())
1767 if niter == niterations:
1768 raise ValueError(
"tried the maximum number of iterations to avoid collisions, increase the distance cutoff")
1772 print(
'shuffling', len(flexible_beads),
'flexible beads')
1773 for fb
in flexible_beads:
1775 if avoidcollision_fb:
1777 other_idxs = all_idxs - fb_idxs
1783 while niter < niterations:
1796 xyz = memb.get_internal_coordinates()
1801 rf = memb.get_rigid_body().get_reference_frame()
1802 glob_to_int = rf.get_transformation_from()
1803 memb.set_internal_coordinates(
1804 glob_to_int.get_transformed(translation))
1806 xyz_transformed=transformation.get_transformed(xyz)
1807 memb.set_internal_coordinates(xyz_transformed)
1808 debug.append([xyz,other_idxs
if avoidcollision_fb
else set()])
1815 debug.append([d,other_idxs
if avoidcollision_fb
else set()])
1821 if avoidcollision_fb:
1823 npairs = len(gcpf.get_close_pairs(mdl,
1831 print(
"shuffle_configuration: floppy body placed close to other %d particles, trying again..." % npairs)
1832 if niter == niterations:
1833 raise ValueError(
"tried the maximum number of iterations to avoid collisions, increase the distance cutoff")
1839 class ColorHierarchy(object):
1841 def __init__(self,hier):
1842 import matplotlib
as mpl
1844 import matplotlib.pyplot
as plt
1848 hier.ColorHierarchy=self
1852 self.method=self.nochange
1860 def get_color(self,fl):
1863 def get_log_scale(self,fl):
1866 return math.log(fl+eps)
1868 def color_by_resid(self):
1869 self.method=self.color_by_resid
1870 self.scheme=self.mpl.cm.rainbow
1871 for mol
in self.mols:
1877 c=self.get_color(float(ri)/self.last)
1881 avr=sum(ris)/len(ris)
1882 c=self.get_color(float(avr)/self.last)
1885 def color_by_uncertainty(self):
1886 self.method=self.color_by_uncertainty
1887 self.scheme=self.mpl.cm.jet
1894 self.first=self.get_log_scale(1.0)
1895 self.last=self.get_log_scale(100.0)
1897 value=self.get_log_scale(unc_dict[p])
1898 if value>=self.last: value=self.last
1899 if value<=self.first: value=self.first
1900 c=self.get_color((value-self.first)/(self.last-self.first))
1903 def get_color_bar(self,filename):
1904 import matplotlib
as mpl
1906 import matplotlib.pyplot
as plt
1909 fig = plt.figure(figsize=(8, 3))
1910 ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15])
1913 norm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)
1915 if self.method == self.color_by_uncertainty:
1916 angticks=[1.0,2.5,5.0,10.0,25.0,50.0,100.0]
1920 vvalue=(self.get_log_scale(at)-self.first)/(self.last-self.first)
1921 if vvalue <= 1.0
and vvalue >= 0.0:
1922 vvalues.append(vvalue)
1923 marks.append(str(at))
1924 cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap,
1927 orientation=
'horizontal')
1928 print(self.first,self.last,marks,vvalues)
1929 cb1.ax.set_xticklabels(marks)
1930 cb1.set_label(
'Angstorm')
1931 plt.savefig(filename, dpi=150, transparent=
True)
1938 """Given a Chimera color name or hex color value, return RGB"""
1939 d = {
'aquamarine': (0.4980392156862745, 1.0, 0.8313725490196079),
1940 'black': (0.0, 0.0, 0.0),
1941 'blue': (0.0, 0.0, 1.0),
1942 'brown': (0.6470588235294118, 0.16470588235294117, 0.16470588235294117),
1943 'chartreuse': (0.4980392156862745, 1.0, 0.0),
1944 'coral': (1.0, 0.4980392156862745, 0.3137254901960784),
1945 'cornflower blue': (0.39215686274509803, 0.5843137254901961, 0.9294117647058824),
1946 'cyan': (0.0, 1.0, 1.0),
1947 'dark cyan': (0.0, 0.5450980392156862, 0.5450980392156862),
1948 'dark gray': (0.6627450980392157, 0.6627450980392157, 0.6627450980392157),
1949 'dark green': (0.0, 0.39215686274509803, 0.0),
1950 'dark khaki': (0.7411764705882353, 0.7176470588235294, 0.4196078431372549),
1951 'dark magenta': (0.5450980392156862, 0.0, 0.5450980392156862),
1952 'dark olive green': (0.3333333333333333, 0.4196078431372549, 0.1843137254901961),
1953 'dark red': (0.5450980392156862, 0.0, 0.0),
1954 'dark slate blue': (0.2823529411764706, 0.23921568627450981, 0.5450980392156862),
1955 'dark slate gray': (0.1843137254901961, 0.30980392156862746, 0.30980392156862746),
1956 'deep pink': (1.0, 0.0784313725490196, 0.5764705882352941),
1957 'deep sky blue': (0.0, 0.7490196078431373, 1.0),
1958 'dim gray': (0.4117647058823529, 0.4117647058823529, 0.4117647058823529),
1959 'dodger blue': (0.11764705882352941, 0.5647058823529412, 1.0),
1960 'firebrick': (0.6980392156862745, 0.13333333333333333, 0.13333333333333333),
1961 'forest green': (0.13333333333333333, 0.5450980392156862, 0.13333333333333333),
1962 'gold': (1.0, 0.8431372549019608, 0.0),
1963 'goldenrod': (0.8549019607843137, 0.6470588235294118, 0.12549019607843137),
1964 'gray': (0.7450980392156863, 0.7450980392156863, 0.7450980392156863),
1965 'green': (0.0, 1.0, 0.0),
1966 'hot pink': (1.0, 0.4117647058823529, 0.7058823529411765),
1967 'khaki': (0.9411764705882353, 0.9019607843137255, 0.5490196078431373),
1968 'light blue': (0.6784313725490196, 0.8470588235294118, 0.9019607843137255),
1969 'light gray': (0.8274509803921568, 0.8274509803921568, 0.8274509803921568),
1970 'light green': (0.5647058823529412, 0.9333333333333333, 0.5647058823529412),
1971 'light sea green': (0.12549019607843137, 0.6980392156862745, 0.6666666666666666),
1972 'lime green': (0.19607843137254902, 0.803921568627451, 0.19607843137254902),
1973 'magenta': (1.0, 0.0, 1.0),
1974 'medium blue': (0.19607843137254902, 0.19607843137254902, 0.803921568627451),
1975 'medium purple': (0.5764705882352941, 0.4392156862745098, 0.8588235294117647),
1976 'navy blue': (0.0, 0.0, 0.5019607843137255),
1977 'olive drab': (0.4196078431372549, 0.5568627450980392, 0.13725490196078433),
1978 'orange red': (1.0, 0.27058823529411763, 0.0),
1979 'orange': (1.0, 0.4980392156862745, 0.0),
1980 'orchid': (0.8549019607843137, 0.4392156862745098, 0.8392156862745098),
1981 'pink': (1.0, 0.7529411764705882, 0.796078431372549),
1982 'plum': (0.8666666666666667, 0.6274509803921569, 0.8666666666666667),
1983 'purple': (0.6274509803921569, 0.12549019607843137, 0.9411764705882353),
1984 'red': (1.0, 0.0, 0.0),
1985 'rosy brown': (0.7372549019607844, 0.5607843137254902, 0.5607843137254902),
1986 'salmon': (0.9803921568627451, 0.5019607843137255, 0.4470588235294118),
1987 'sandy brown': (0.9568627450980393, 0.6431372549019608, 0.3764705882352941),
1988 'sea green': (0.1803921568627451, 0.5450980392156862, 0.3411764705882353),
1989 'sienna': (0.6274509803921569, 0.3215686274509804, 0.17647058823529413),
1990 'sky blue': (0.5294117647058824, 0.807843137254902, 0.9215686274509803),
1991 'slate gray': (0.4392156862745098, 0.5019607843137255, 0.5647058823529412),
1992 'spring green': (0.0, 1.0, 0.4980392156862745),
1993 'steel blue': (0.27450980392156865, 0.5098039215686274, 0.7058823529411765),
1994 'tan': (0.8235294117647058, 0.7058823529411765, 0.5490196078431373),
1995 'turquoise': (0.25098039215686274, 0.8784313725490196, 0.8156862745098039),
1996 'violet red': (0.8156862745098039, 0.12549019607843137, 0.5647058823529412),
1997 'white': (1.0, 1.0, 1.0),
1998 'yellow': (1.0, 1.0, 0.0)}
1999 if colorname.startswith(
'#'):
2000 return tuple(int(colorname[i:i+2], 16) / 255.
for i
in (1, 3, 5))
static bool get_is_setup(const IMP::ParticleAdaptor &p)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
A decorator to associate a particle with a part of a protein/DNA/RNA.
Extends the functionality of IMP.atom.Molecule.
def add_script_provenance
Tag the given particle with the current Python script.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
void add_particles(RMF::FileHandle fh, const ParticlesTemp &hs)
Set of Python classes to create a multi-state, multi-resolution IMP hierarchy.
static Weight setup_particle(Model *m, ParticleIndex pi)
A decorator for a particle which has bonds.
Rotation3D get_random_rotation_3d(const Rotation3D ¢er, double distance)
Pick a rotation at random near the provided one.
std::string get_module_version()
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
static Surface setup_particle(Model *m, ParticleIndex pi)
Add uncertainty to a particle.
void add_particle(RMF::FileHandle fh, Particle *hs)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
This class initializes the root node of the global IMP.atom.Hierarchy.
def add_imp_provenance
Tag the given particle as being created by the current version of IMP.
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
Add resolution to a particle.
Bond create_bond(Bonded a, Bonded b, Bond o)
Connect the two wrapped particles by a custom bond.
Object used to hold a set of restraints.
algebra::GridD< 3, algebra::DenseGridStorageD< 3, float >, float > get_grid(DensityMap *in_map)
Return a dense grid containing the voxels of the passed density map.
Stores a named protein chain.
static bool get_is_setup(Model *m, ParticleIndex pi)
def add_software_provenance
Tag the given particle with the software used to create it.
A decorator for keeping track of copies of a molecule.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
The standard decorator for manipulating molecular structures.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
A decorator for a particle representing an atom.
void transform(XYZ a, const algebra::Transformation3D &tr)
Apply a transformation to the particle.
static Bonded setup_particle(Model *m, ParticleIndex pi)
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.
static Scale setup_particle(Model *m, ParticleIndex pi)
A decorator for a particle that is part of a rigid body but not rigid.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
Find all nearby pairs by testing all pairs.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
A decorator for a residue.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
static bool get_is_setup(const IMP::ParticleAdaptor &p)
static bool get_is_setup(Model *m, ParticleIndex p)
Check if the particle has the needed attributes for a cast to succeed.
The general base class for IMP exceptions.
Rotation3D get_identity_rotation_3d()
Return a rotation that does not do anything.
void link_hierarchies(RMF::FileConstHandle fh, const atom::Hierarchies &hs)
Class to handle individual particles of a Model object.
Bond get_bond(Bonded a, Bonded b)
Get the bond between two particles.
Stores a list of Molecules all with the same State index.
std::string get_data_path(std::string file_name)
Return the full path to one of this module's data files.
int get_copy_index(Hierarchy h)
Walk up the hierarchy to find the current copy index.
Python classes to represent, score, sample and analyze models.
static bool get_is_setup(Model *m, ParticleIndex pi)
double get_resolution(Model *m, ParticleIndex pi)
Estimate the resolution of the hierarchy as used by Representation.
A decorator for a rigid body.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Hierarchies get_leaves(const Selection &h)
A decorator for a molecule.
Select hierarchy particles identified by the biological name.
Support for the RMF file format for storing hierarchical molecular data and markup.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Warning for probably incorrect input parameters.
Transformation3D get_random_local_transformation(Vector3D origin, double max_translation=5., double max_angle_in_rad=0.26)
Get a local transformation.
Temporarily stores residue information, even without structure available.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...