def intra_both(b1, b2, dscale, kspring=1, nbead=ndomain): '''give f100 restraint to both copies''' upperdist = dscale * (Rb[b1] + Rb[b2]) ds = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(upperdist,kspring)) dst = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(.1,ktouch)) p1 = chain.get_particle(b1) p2 = chain.get_particle(b2) apair = IMP.ParticlePair(p1, p2) pr = IMP.core.PairRestraint(ds, apair) prt = IMP.core.PairRestraint(dst, apair) m.add_restraint(pr) #m.add_restraint(prt) #touchRestraints.append(prt) c1 = b1 + nbead c2 = b2 + nbead p1 = chain.get_particle(c1) p2 = chain.get_particle(c2) apair = IMP.ParticlePair(p1, p2) pr = IMP.core.PairRestraint(ds, apair) prt = IMP.core.PairRestraint(dst, apair) m.add_restraint(pr) #m.add_restraint(prt) #touchRestraints.append(prt) #print "Add fmax",b1,"-",b2 inbothRestraints.append([b1, b2])
def __init__( self, representation, selection_tuple, stringsequence=None, strength=10.0): self.m = representation.prot.get_model() self.rs = IMP.RestraintSet(self.m, "Angles") self.weight = 1 self.label = "None" self.pairslist = [] particles = IMP.pmi.tools.select_by_tuple( representation, selection_tuple, resolution=1) if stringsequence is None: stringsequence = "T" * (len(particles) - 3) for n, ps in enumerate(IMP.pmi.tools.sublist_iterator(particles, 4, 4)): quadruplet = [] if len(ps) != 4: print "ResidueDihedralRestraint: wrong length of quadruplet" exit() for p in ps: if not IMP.atom.Residue.get_is_setup(p): print "ResidueDihedralRestraint: not a residue" exit() else: quadruplet.append(p) dihedraltype = stringsequence[n] if dihedraltype == "C": anglemin = -20.0 anglemax = 20.0 ts = IMP.core.HarmonicWell( (self.pi * anglemin / 180.0, self.pi * anglemax / 180.0), strength) print "ResidueDihedralRestraint: adding a CYS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(), quadruplet[2].get_name(), quadruplet[3].get_name()) if dihedraltype == "T": anglemin = 180 - 70.0 anglemax = 180 + 70.0 ts = IMP.core.HarmonicWell( (self.pi * anglemin / 180.0, self.pi * anglemax / 180.0), strength) print "ResidueDihedralRestraint: adding a TRANS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(), quadruplet[2].get_name(), quadruplet[3].get_name()) self.rs.add_restraint( IMP.core.DihedralRestraint(ts, quadruplet[0], quadruplet[1], quadruplet[2], quadruplet[3])) self.pairslist.append( IMP.ParticlePair(quadruplet[0], quadruplet[3])) self.pairslist.append( IMP.ParticlePair(quadruplet[3], quadruplet[0]))
def __init__(self, objects, anglemin=100.0, anglemax=140.0, strength=10.0): particles = IMP.pmi.tools.input_adaptor(objects, 1, flatten=True) self.m = particles[0].get_model() self.rs = IMP.RestraintSet(self.m, "Angles") self.weight = 1 self.label = "None" self.pairslist = [] ts = IMP.core.HarmonicWell( (math.pi * anglemin / 180.0, math.pi * anglemax / 180.0), strength) for ps in IMP.pmi.tools.sublist_iterator(particles, 3, 3): triplet = [] if len(ps) != 3: raise ValueError("wrong length of triplet") for p in ps: if not IMP.atom.Residue.get_is_setup(p): raise TypeError("%s is not a residue" % p) else: triplet.append(p) print( "ResidueAngleRestraint: adding a restraint between %s %s %s" % (triplet[0].get_name(), triplet[1].get_name(), triplet[2].get_name())) self.rs.add_restraint( IMP.core.AngleRestraint(triplet[0].get_model(), ts, triplet[0], triplet[1], triplet[2])) self.pairslist.append(IMP.ParticlePair(triplet[0], triplet[2])) self.pairslist.append(IMP.ParticlePair(triplet[2], triplet[0]))
def __init__(self, objects, stringsequence=None, strength=10.0): particles = IMP.pmi.tools.input_adaptor(objects, 1, flatten=True) self.m = particles[0].get_model() self.rs = IMP.RestraintSet(self.m, "Angles") self.weight = 1 self.label = "None" self.pairslist = [] if stringsequence is None: stringsequence = "T" * (len(particles) - 3) for n, ps in enumerate(IMP.pmi.tools.sublist_iterator(particles, 4, 4)): quadruplet = [] if len(ps) != 4: raise ValueError("wrong length of quadruplet") for p in ps: if not IMP.atom.Residue.get_is_setup(p): raise TypeError("%s is not a residue" % p) else: quadruplet.append(p) dihedraltype = stringsequence[n] if dihedraltype == "C": anglemin = -20.0 anglemax = 20.0 ts = IMP.core.HarmonicWell( (math.pi * anglemin / 180.0, math.pi * anglemax / 180.0), strength) print("ResidueDihedralRestraint: adding a CYS restraint " "between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(), quadruplet[2].get_name(), quadruplet[3].get_name())) if dihedraltype == "T": anglemin = 180 - 70.0 anglemax = 180 + 70.0 ts = IMP.core.HarmonicWell( (math.pi * anglemin / 180.0, math.pi * anglemax / 180.0), strength) print("ResidueDihedralRestraint: adding a TRANS restraint " "between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(), quadruplet[2].get_name(), quadruplet[3].get_name())) self.rs.add_restraint( IMP.core.DihedralRestraint(self.m, ts, quadruplet[0], quadruplet[1], quadruplet[2], quadruplet[3])) self.pairslist.append( IMP.ParticlePair(quadruplet[0], quadruplet[3])) self.pairslist.append( IMP.ParticlePair(quadruplet[3], quadruplet[0]))
def __init__(self, hierarchy, selection_tuples=None, resolution=1, strength=0.01, dist_cutoff=10.0, ca_only=True): """Constructor @param hierarchy Root hierarchy to select from @param selection_tuples Selecting regions for the restraint [[start,stop,molname,copy_index=0],...] @param resolution Resolution for applying restraint @param strength Bond strength @param dist_cutoff Cutoff for making restraints @param ca_only Selects only CAlphas. Only matters if resolution=0. """ particles = [] self.m = hierarchy.get_model() for st in selection_tuples: copy_index = 0 if len(st) > 3: copy_index = st[3] if not ca_only: sel = IMP.atom.Selection(hierarchy, molecule=st[2], residue_indexes=range( st[0], st[1] + 1), copy_index=copy_index) else: sel = IMP.atom.Selection(hierarchy, molecule=st[2], residue_indexes=range( st[0], st[1] + 1), copy_index=copy_index, atom_type=IMP.atom.AtomType("CA")) particles += sel.get_selected_particles() self.weight = 1 self.label = "None" self.pairslist = [] # create score self.rs = IMP.pmi.create_elastic_network(particles, dist_cutoff, strength) for r in self.rs.get_restraints(): a1, a2 = r.get_inputs() self.pairslist.append(IMP.ParticlePair(a1, a2)) self.pairslist.append(IMP.ParticlePair(a2, a1)) print('ElasticNetwork: created', self.rs.get_number_of_restraints(), 'restraints')
def __init__(self,representation=None, selection_tuples=None, resolution=1, strength=0.01, dist_cutoff=10.0, ca_only=True, hierarchy=None): """Constructor @param representation Representation object @param selection_tuples Selecting regions for the restraint @param resolution Resolution for applying restraint @param strength Bond strength @param dist_cutoff Cutoff for making restraints @param ca_only Selects only CAlphas. Only matters if resolution=0. @param hierarchy Root hierarchy to select from, use this instead of representation """ particles = [] if representation is None and hierarchy is not None: self.m = hierarchy.get_model() for st in selection_tuples: if not ca_only: sel = IMP.atom.Selection(hierarchy,chain=st[0],residue_indexes=range(st[1],st[2]+1)) else: sel = IMP.atom.Selection(hierarchy,chain=st[0],residue_indexes=range(st[1],st[2]+1), atom_type=IMP.atom.AtomType("CA")) particles+=sel.get_selected_particles() elif representation is not None and type(representation)==IMP.pmi.representation.Representation: self.m = representation.mdl for st in selection_tuples: print('selecting with',st) for p in IMP.pmi.tools.select_by_tuple(representation,st,resolution=resolution): if (resolution==0 and ca_only and IMP.atom.Atom(p).get_atom_type()!=IMP.atom.AtomType("CA")): continue else: particles.append(p.get_particle()) else: raise Exception("must pass representation or hierarchy") self.weight = 1 self.label = "None" self.pairslist = [] # create score self.rs = IMP.pmi.create_elastic_network(particles,dist_cutoff,strength) for r in self.rs.get_restraints(): a1,a2 = r.get_inputs() self.pairslist.append(IMP.ParticlePair(a1,a2)) self.pairslist.append(IMP.ParticlePair(a2,a1)) print('created',self.rs.get_number_of_restraints(),'restraints')
def _get_beadDistanceRestraint(self, bead1, bead2, dist, kspring=1): """ get distance upper bound restraint to bead1 and bead2 Parameters ----------- bead1,bead2 : int bead id dist : int distance upper bound kspring : int harmonic constant k Return ------ restraint """ restraintName = "Bead (%d,%d) : %f k = %.1f" % (bead1, bead2, dist, kspring) ds = IMP.core.SphereDistancePairScore( IMP.core.HarmonicUpperBound(dist, kspring)) pr = IMP.core.PairRestraint( self.model, ds, IMP.ParticlePair(self.chain.get_indexes()[bead1], self.chain.get_indexes()[bead2]), restraintName) return pr
def _get_minPairRestraints(self, bpair, dist, minnum, kspring=1): """ Return restraint decorater of min pair restraints for minnum out of bpairs are satisfied Parameters ----------- bpair : tuple list contact pair candidates dist : int distance upperbound for contact minnum : int minimun number of pairs required to satisify contactRange : int scale of (r1+r2) where a contact is defined """ ambi = IMP.container.ListPairContainer(self.model) restraintName = "Bead [ " for p in bpair: restraintName += "(%d,%d) " % (p[0], p[1]) p0 = self.chain.get_particles()[p[0]] p1 = self.chain.get_particles()[p[1]] pair = IMP.ParticlePair(p0, p1) ambi.add(pair) restraintName += "] : %f k = %.1f" % (dist, kspring) ds = IMP.core.SphereDistancePairScore( IMP.core.HarmonicUpperBound(dist, kspring)) minpr = IMP.container.MinimumPairRestraint(ds, ambi, minnum, restraintName) return minpr
def get_CA_force_field(self): bondrslist = [] anglrslist = [] diherslist = [] pairslist = [] # add bonds for res in range(0, len(self.particles) - 1): ps = self.particles[res:res + 2] pairslist.append(IMP.ParticlePair(ps[0], ps[1])) pairslist.append(IMP.ParticlePair(ps[1], ps[0])) br = self.get_distance_restraint(ps[0], ps[1], 3.78, 416.0) br.set_name('Bond_restraint') bondrslist.append(br) # add dihedrals for res in range(0, len(self.particles) - 4): # if res not in dihe_dict: continue # get the appropriate parameters # get the particles ps = self.particles[res:res + 5] [phi0, phi1, score_dih] = self.read_potential_dihedral( self.ssstring[res:res + 4], True) pairslist.append(IMP.ParticlePair(ps[0], ps[3])) pairslist.append(IMP.ParticlePair(ps[3], ps[0])) pairslist.append(IMP.ParticlePair(ps[1], ps[4])) pairslist.append(IMP.ParticlePair(ps[4], ps[1])) dr = IMP.isd_emxl.CADihedralRestraint( ps[0], ps[1], ps[2], ps[3], ps[4], phi0, phi1, score_dih) dr.set_name('Dihedral restraint') diherslist.append(dr) # add angles for res in range(0, len(self.particles) - 2): ps = self.particles[res:res + 3] [psi, score_ang] = self.read_potential_angle( self.ssstring[res:res + 2], True) pairslist.append(IMP.ParticlePair(ps[0], ps[2])) pairslist.append(IMP.ParticlePair(ps[2], ps[0])) dr = IMP.isd_emxl.CAAngleRestraint( ps[0], ps[1], ps[2], psi, score_ang) dr.set_name('Angle restraint') anglrslist.append(dr) return (bondrslist, anglrslist, diherslist, pairslist)
def connect_beads(m, b1, b2): # score = score_HUBSD_default r = IMP.core.PairRestraint( score_HUBSDS_default, IMP.ParticlePair(b1.get_particle(), b2.get_particle())) m.add_restraint(r) m.set_maximum_score(r, default_spring_constant) return r
def __init__(self, representation, selection_tuple, distance=3.78, strength=10.0, jitter=None): """Constructor @param representation @param selection_tuple Requested selection @param distance Resting distance for restraint @param strength Bond constant @param jitter Defines the +- added to the optimal distance in the harmonic well restraint used to increase the tolerance """ self.m = representation.prot.get_model() self.rs = IMP.RestraintSet(self.m, "Bonds") self.weight = 1 self.label = "None" self.pairslist = [] particles = IMP.pmi.tools.select_by_tuple( representation, selection_tuple, resolution=1) if not jitter: ts = IMP.core.Harmonic(distance, strength) else: ts = IMP.core.HarmonicWell( (distance - jitter, distance + jitter), strength) for ps in IMP.pmi.tools.sublist_iterator(particles, 2, 2): pair = [] if len(ps) != 2: raise ValueError("wrong length of pair") for p in ps: if not IMP.atom.Residue.get_is_setup(p): raise TypeError("not a residue") else: pair.append(p) print("ResidueBondRestraint: adding a restraint between %s %s" % (pair[0].get_name(), pair[1].get_name())) self.rs.add_restraint( IMP.core.DistanceRestraint(self.m, ts, pair[0], pair[1])) self.pairslist.append(IMP.ParticlePair(pair[0], pair[1])) self.pairslist.append(IMP.ParticlePair(pair[1], pair[0]))
def restrain_d(b1, b2, d, kspring=1): '''give d restraint to both copies''' upperdist = d ds = IMP.core.SphereDistancePairScore( IMP.core.HarmonicUpperBound(upperdist, kspring)) p1 = chain.get_particle(b1) p2 = chain.get_particle(b2) apair = IMP.ParticlePair(p1, p2) pr = IMP.core.PairRestraint(ds, apair) m.add_restraint(pr)
def __init__( self, representation, selection_tuple, anglemin=100.0, anglemax=140.0, strength=10.0): self.m = representation.prot.get_model() self.rs = IMP.RestraintSet(self.m, "Angles") self.weight = 1 self.label = "None" self.pairslist = [] particles = IMP.pmi.tools.select_by_tuple( representation, selection_tuple, resolution=1) ts = IMP.core.HarmonicWell( (self.pi * anglemin / 180.0, self.pi * anglemax / 180.0), strength) for ps in IMP.pmi.tools.sublist_iterator(particles, 3, 3): triplet = [] if len(ps) != 3: print "ResidueAngleRestraint: wrong length of triplet" exit() for p in ps: if not IMP.atom.Residue.get_is_setup(p): print "ResidueAngleRestraint: not a residue" exit() else: triplet.append(p) print "ResidueAngleRestraint: adding a restraint between %s %s %s" % (triplet[0].get_name(), triplet[1].get_name(), triplet[2].get_name()) self.rs.add_restraint( IMP.core.AngleRestraint(ts, triplet[0], triplet[1], triplet[2])) self.pairslist.append(IMP.ParticlePair(triplet[0], triplet[2])) self.pairslist.append(IMP.ParticlePair(triplet[2], triplet[0]))
def set_close_pairs_excluded_volume_restraint(self, distance=10, weight=1.0, ratio=0.05, stddev=2, max_score=False): """ Creates an excluded volume restraint between all the components of the coarse assembly.See help for @param distance Maximum distance tolerated between particles @param weight Weight for the restraint @param stddev @param max_score Maximum value for the restraint. If the parameter is None, an automatic value is computed (using the ratio). @param ratio Fraction of the number of possible pairs of particles that are tolerated to overlap. The maximum score is modified according to this ratio. I have found that ratios of 0.05-0.1 work well allowing for some interpenetration @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ k = core.Harmonic.get_k_from_standard_deviation(stddev) for i, c1 in enumerate(self.coarse_assembly.get_children()): for j, c2 in enumerate(self.coarse_assembly.get_children()): if j > i: name = "exc_vol_%s_%s" % (c1.get_name(), c2.get_name()) ls1 = atom.get_leaves(c1) ls2 = atom.get_leaves(c2) possible_pairs = len(ls1) * len(ls2) n_pairs = possible_pairs * ratio marker1 = IMP.Particle( self.model, "marker1 " + name) marker2 = IMP.Particle( self.model, "marker2 " + name) table_refiner = core.TableRefiner() table_refiner.add_particle(marker1, ls1) table_refiner.add_particle(marker2, ls2) score = core.HarmonicLowerBound(distance, k) pair_score = core.SphereDistancePairScore(score) close_pair_score = core.ClosePairsPairScore(pair_score, table_refiner, distance) r = core.PairRestraint(close_pair_score, IMP.ParticlePair(marker1, marker2)) if not max_score: minimum_distance_allowed = 0 max_score = weight * n_pairs * \ score.evaluate(minimum_distance_allowed) log.debug("Setting close_pairs_excluded_volume_restraint(), " "max_score %s", max_score) self.add_restraint(r, name, weight, max_score)
def restrain_one(b1, b2, dscale, kspring=1.0): '''give f100 restraint to one pair''' upperdist = dscale * (Rb[b1] + Rb[b2]) ds = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(upperdist,kspring)) dst = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(.1,ktouch)) p1 = chain.get_particle(b1) p2 = chain.get_particle(b2) apair = IMP.ParticlePair(p1, p2) pr = IMP.core.PairRestraint(ds, apair) prt = IMP.core.PairRestraint(dst, apair) m.add_restraint(pr)
def set_pair_score_restraint(self, name1, name2, restraint_name, distance=10, weight=1.0, n_pairs=1, stddev=2, max_score=None): """ Set a pair_score restraint between the coarse representation of two components @param name1 Name of the first component @param name2 Name of the second component @param restraint_name Name for the restraint @param distance Maximum distance tolerated between particles @param weight Weight of the restraint @param n_pairs @param max_score Maximum value tolerated for the restraint @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ table_refiner = core.TableRefiner() # The particles in A are attached to a marker particle via a refiner. # When the refiner gets a request for marker1, it returns the attached # particles A = representation.get_component(self.coarse_assembly, name1) marker1 = IMP.Particle(self.model, "marker1 " + restraint_name) table_refiner.add_particle(marker1, atom.get_leaves(A)) # same for B B = representation.get_component(self.coarse_assembly, name2) marker2 = IMP.Particle(self.model, "marker2 " + restraint_name) table_refiner.add_particle(marker2, atom.get_leaves(B)) k = core.Harmonic.get_k_from_standard_deviation(stddev) score = core.HarmonicUpperBoundSphereDistancePairScore(distance, k) # The score is set for the n_pairs closest pairs of particles pair_score = core.KClosePairsPairScore(score, table_refiner, n_pairs) # When KClosePairsPairScore is called, the refiner will provide the # particles for A and B if not max_score: # Build a maximum score based on the function type that is used, # an HarmonicUpperBound temp_score = core.HarmonicUpperBound(distance, k) error_distance_allowed = 10 max_score = weight * n_pairs * \ temp_score.evaluate(distance + error_distance_allowed) log.info("Setting pair score restraint for %s %s. k = %s, max_score " "= %s, stddev %s", name1, name2, k, max_score, stddev) r = core.PairRestraint( pair_score, IMP.ParticlePair( marker1, marker2)) self.add_restraint(r, restraint_name, weight, max_score)
def set_xlink_restraint(self, id1, chain1, residue1, id2, chain2, residue2, distance, weight, stddev, max_score=False): """ Set a restraint on the maximum distance between 2 residues @param id1 Name of the first component @param chain1 @param residue1 Residue number for the aminoacid in the first component.The number is the number in the PDB file, not the number relative to the beginning of the chain @param id2 Name of the second component @param chain2 @param residue2 Residue number for the aminoacid in the second component. @param distance Maximum distance tolerated @param weight Weight of the restraint @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian @param max_score See help for add_restraint(). If none is given, the maximum score is set to allow a maximum distance of 10 Angstrom greater than the parameter "distance". """ xlink = buildxlinks.Xlink( id1, chain1, residue1, id2, chain2, residue2, distance) log.info("Setting cross-linking restraint ") log.info("%s", xlink.show()) self.xlinks_dict.add(xlink) # setup restraint A = representation.get_component(self.assembly, xlink.first_id) s1 = IMP.atom.Selection(A, chain=xlink.first_chain, residue_index=xlink.first_residue) p1 = s1.get_selected_particles()[0] B = representation.get_component(self.assembly, xlink.second_id) s2 = IMP.atom.Selection(B, chain=xlink.second_chain, residue_index=xlink.second_residue) p2 = s2.get_selected_particles()[0] k = core.Harmonic.get_k_from_standard_deviation(stddev) score = core.HarmonicUpperBound(xlink.distance, k) pair_score = IMP.core.DistancePairScore(score) r = IMP.core.PairRestraint(pair_score, IMP.ParticlePair(p1, p2)) if not max_score: error_distance_allowed = 100 max_score = weight * \ score.evaluate(distance + error_distance_allowed) log.info("%s, max_score %s", xlink.show(), max_score) self.add_restraint(r, xlink.get_name(), weight, max_score)
def __init__(self, objects, distance=3.78, strength=10.0, jitter=None): """Constructor @param objects Objects to restrain @param distance Resting distance for restraint @param strength Bond constant @param jitter Defines the +- added to the optimal distance in the harmonic well restraint used to increase the tolerance """ particles = IMP.pmi.tools.input_adaptor(objects, 1, flatten=True) self.m = particles[0].get_model() self.rs = IMP.RestraintSet(self.m, "Bonds") self.weight = 1 self.label = "None" self.pairslist = [] if not jitter: ts = IMP.core.Harmonic(distance, strength) else: ts = IMP.core.HarmonicWell((distance - jitter, distance + jitter), strength) for ps in IMP.pmi.tools.sublist_iterator(particles, 2, 2): pair = [] if len(ps) != 2: raise ValueError("wrong length of pair") for p in ps: if not IMP.atom.Residue.get_is_setup(p): raise TypeError("%s is not a residue" % p) else: pair.append(p) print("ResidueBondRestraint: adding a restraint between %s %s" % (pair[0].get_name(), pair[1].get_name())) self.rs.add_restraint( IMP.core.DistanceRestraint(self.m, ts, pair[0], pair[1])) self.pairslist.append(IMP.ParticlePair(pair[0], pair[1])) self.pairslist.append(IMP.ParticlePair(pair[1], pair[0]))
def __init__(self,representation, selection_tuples, resolution=1, strength=10.0, dist_cutoff=10.0, ca_only=True): ''' ca_only: only applies for resolution 0 ''' self.m = representation.prot.get_model() self.rs = IMP.RestraintSet(self.m, "ElasticNetwork") self.weight = 1 self.label = "None" self.pairslist = [] particles = [] for st in selection_tuples: for p in IMP.pmi.tools.select_by_tuple(representation, st,resolution=resolution): if resolution==0 and ca_only \ and IMP.atom.Atom(p).get_atom_type()!=IMP.atom.AtomType("CA"): continue else: particles.append(p.get_particle()) for pair in itertools.combinations(particles,2): distance=IMP.algebra.get_distance(IMP.core.XYZ(pair[0]).get_coordinates(), IMP.core.XYZ(pair[1]).get_coordinates()) if distance>=dist_cutoff: continue ts=IMP.core.HarmonicDistancePairScore(distance,strength) print "ElasticNetworkConstraint: adding a restraint between %s and %s with distance %.3f" % (pair[0].get_name(),pair[1].get_name(),distance) self.rs.add_restraint(IMP.core.PairRestraint(ts,pair)) self.pairslist.append(IMP.ParticlePair(pair[0], pair[1])) self.pairslist.append(IMP.ParticlePair(pair[1], pair[0])) print 'created',self.rs.get_number_of_restraints(),'restraints'
def create_hierarchy(self, m): linkers_hierarchy_name = "hierarchy linker " + self.get_name() # hl=IMP.atom.Fragment.setup_particle( IMP.Particle(m,linkers_hierarchy_name) ) hl = IMP.atom.Hierarchy.setup_particle( IMP.Particle(m, linkers_hierarchy_name)) # # create linker beads # for lbi in range(self.__nb_beads_in_linker): p = IMP.Particle(m, self.__name + " " + str(lbi)) xyzd = IMP.core.XYZR.setup_particle(p) xyzd.set_radius(linker_bead_radius) xyzd.set_coordinates_are_optimized(True) IMP.atom.Mass.setup_particle(p, linker_bead_mass) # hlr = IMP.atom.Residue.setup_particle( p ) hlr = IMP.atom.Hierarchy.setup_particle(p) hl.add_child(hlr) self.__particles.append(p) # print "LINKER BEAD",p.get_name(),xyzd.show() # # glue beads # # def __connect_linker_particles(m,pi1,pi2): # r = IMP.core.PairRestraint( score_HUBSDS_default, # IMP.ParticlePair(self.__particles[pi1],self.__particles[pi2]) # ) # r.set_name("linker restraint <"+self.get_name()+">["+str( (pi1,pi2) )+"]") # m.add_restraint(r) # m.set_maximum_score(r, default_spring_constant) # return r # for lbi in range(self.__nb_beads_in_linker-1) : # r = __connect_linker_particles(m,lbi,lbi+1) # self.__restraints.append(r) ## print "LINKER RESTRAINT : ",self.__name,len(self.__restraints) pps = [ IMP.ParticlePair(self.__particles[pi], self.__particles[pi + 1]) for pi in range(self.__nb_beads_in_linker - 1) ] lpps = IMP.container.ListPairContainer(pps) r = IMP.container.PairsRestraint(score_HUBSDS_default, lpps) r.set_name("linker restraint <" + self.get_name() + ">") m.add_restraint(r) m.set_maximum_score(r, default_spring_constant) self.__restraints.append(r) return hl, self.__restraints
def fix_distance_between_beads(self, b1, b2, name=None): """ """ if name == None: name = self.get_name() x1 = self.get_bead(b1).get_XYZR() x2 = self.get_bead(b2).get_XYZR() vector = x1.get_coordinates() - x2.get_coordinates() inter_beads_distance = vector.get_magnitude() score = IMP.core.HarmonicDistancePairScore(inter_beads_distance, default_spring_constant) r = IMP.core.PairRestraint( score, IMP.ParticlePair(x1, x2), "rigidity restraint " + name + " " + str(b1) + "-" + str(b2)) self.__m.add_restraint(r) self.__m.set_maximum_score(r, default_spring_constant) return r
def minpair(lpair, to_n, dscale, kspring=1.0): '''give restraint to to_n=1,2,3,or 4 of lpair possible pairs''' ambi = IMP.container.ListPairContainer() for p in lpair: pi = chain.get_particle(p[0]) pj = chain.get_particle(p[1]) pair = IMP.ParticlePair(pi, pj) ambi.add_particle_pair(pair) upperdist = dscale * (Rb[p[0]] + Rb[p[1]]) ds = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(upperdist,kspring)) dst = IMP.core.SphereDistancePairScore\ (IMP.core.HarmonicUpperBound(.1,ktouch)) minpr = IMP.container.MinimumPairRestraint(ds, ambi, to_n) minprt = IMP.container.MinimumPairRestraint(dst, ambi, to_n) m.add_restraint(minpr) #m.add_restraint(minprt) #touchRestraints.append(minprt) minpairRestraints.append([lpair, to_n])
def get_LJ_restraint_all_particles(mi): """ Lennard-johnes all protein domains in a model """ sf = IMP.atom.ForceSwitch(60.0, 70.0) LJS = IMP.atom.LennardJonesPairScore(sf) well_depth = 1 default_LJ_constant = 1.0 # In a first approximation we will stick everybody, particles = [] for subunit_info in mi.itervalues(): for p in subunit_info.get_particles(): IMP.atom.LennardJones.setup_particle(p, well_depth) particles.append(p) # particles.extend( p ) for i in range(1, len(particles)): for j in range(i): r = IMP.core.PairRestraint( LJS, IMP.ParticlePair(particles[j], particles[i])) mi.get_model().add_restraint(r) mi.get_model().set_maximum_score(r, default_LJ_constant)
def create_hierarchy(self, m): """Creates a set of particles and restraints to model the current protein in a given IMP model object @param m: the IMP model in which the particles are created @return : a pair (h,r) comprising the hierarchy for the particle and the internal cohesion restraints""" emote("create molecule " + self.__name) self.__m = m # root = IMP.atom.Hierarchy.setup_particle( IMP.Particle(m) ) root = IMP.atom.Molecule.setup_particle(IMP.Particle(m, self.__name)) beads_hierarchy = IMP.atom.Hierarchy.setup_particle( IMP.Particle(m, self.__name)) beadParticles = [] for i in range(0, self.get_number_of_beads()): b = self.__beads[i] pb = IMP.Particle(m) hb = IMP.atom.Hierarchy.setup_particle(pb) # hb = IMP.atom.Fragment.setup_particle(pb) name = self.get_name() + "-" + b.get_name() + "(" + str(i) + ")" hb.set_name(name) xyzd = IMP.core.XYZR.setup_particle(pb) xyzd.set_radius(b.get_radius()) xyzd.set_coordinates_are_optimized(True) IMP.atom.Mass.setup_particle(pb, b.get_mass()) beads_hierarchy.add_child(hb) beadParticles.append(pb) b.assign_particle(pb) emote(name + " r:" + str(b.get_radius()) + " m:" + str(b.get_mass())) # IMP.atom.Molecule.setup_particle(root) # root.set_name(self.__name) root.add_child(beads_hierarchy) self.__beads_hierarchy = beads_hierarchy restraints = [] for link in self.__link: bead_i_1, bead_i_2, size = link # score = IMP.core.HarmonicUpperBoundSphereDistancePairScore( compute_link_max_len(size),default_spring_constant ) score = score_HUBSDS_default r = IMP.core.PairRestraint( score, IMP.ParticlePair(beadParticles[bead_i_1], beadParticles[bead_i_2])) r.set_name("cohesion restraint(" + self.get_name() + ")[" + str(bead_i_1) + "," + str(bead_i_2) + "]") m.add_restraint(r) m.set_maximum_score(r, default_spring_constant) restraints.append(r) emote("inserted " + str(len(self.__link)) + " bead connection restraints in the system for " + self.get_name()) hl = IMP.atom.Hierarchy.setup_particle( IMP.Particle(m, "L " + self.get_name())) for l in self.__linkers: hlr, rl = l.create_hierarchy(m) restraints.extend(rl) hl.add_child(hlr) # l.create_hierarchy(m) # then attach the linker to its two connected beads b1, b2 = l.get_linked_bead_indices() for bi, lbi in ((b1, 0), (b2, l.get_number_of_particles() - 1)): r = IMP.core.PairRestraint( score, IMP.ParticlePair(beadParticles[bi], l.get_particles()[lbi])) m.add_restraint(r) m.set_maximum_score(r, default_spring_constant) restraints.append(r) r.set_name("linker attach (" + self.get_name() + ")[" + str((bi, lbi)) + "]") self.__linkers_hierarchy = hl root.add_child(hl) self.__hierarchy = root return root, restraints
def __init__(self, representation, selection_tuples, resolution=1, strength=0.01, dist_cutoff=10.0, ca_only=True): ''' ca_only: only applies for resolution 0 ''' self.m = representation.prot.get_model() self.rs = IMP.RestraintSet(self.m, "ElasticNetwork") self.weight = 1 self.label = "None" self.pairslist = [] particles = [] for st in selection_tuples: print('selecting with', st) for p in IMP.pmi.tools.select_by_tuple(representation, st, resolution=resolution): if (resolution == 0 and ca_only and IMP.atom.Atom(p).get_atom_type() != IMP.atom.AtomType("CA")): continue else: particles.append(p.get_particle()) gcpf = IMP.core.GridClosePairsFinder() gcpf.set_distance(dist_cutoff) particleindexes = IMP.get_indexes(particles) pairs = gcpf.get_close_pairs(self.m, particleindexes, particleindexes) for pair in pairs: p1 = self.m.get_particle(pair[0]) p2 = self.m.get_particle(pair[1]) if p1 == p2: print("%s and %s are the same particle" % (p1.get_name(), p2.get_name())) continue if (IMP.core.RigidMember.get_is_setup(p1) and IMP.core.RigidMember.get_is_setup(p2) and IMP.core.RigidMember(p1).get_rigid_body() == IMP.core.RigidMember(p2).get_rigid_body()): print("%s and %s are in the same rigid body" % (p1.get_name(), p2.get_name())) continue distance = IMP.algebra.get_distance( IMP.core.XYZ(p1).get_coordinates(), IMP.core.XYZ(p2).get_coordinates()) ts = IMP.core.HarmonicDistancePairScore(distance, strength) print( "ElasticNetworkConstraint: adding a restraint between %s and %s with distance %.3f" % (p1.get_name(), p2.get_name(), distance)) self.rs.add_restraint(IMP.core.PairRestraint(self.m, ts, (p1, p2))) self.pairslist.append(IMP.ParticlePair(p1, p2)) self.pairslist.append(IMP.ParticlePair(p1, p2)) print('created', self.rs.get_number_of_restraints(), 'restraints')
def get_distance_restraint(self, p0, p1, d0, kappa): h = IMP.core.Harmonic(d0, kappa) dps = IMP.core.DistancePairScore(h) pr = IMP.core.PairRestraint(self.m, dps, IMP.ParticlePair(p0, p1)) return pr
m = IMP.Model() p1 = IMP.kernel.Particle(m) p2 = IMP.kernel.Particle(m) xyz1 = IMP.core.XYZ.setup_particle(p1) xyz2 = IMP.core.XYZ.setup_particle(p2) xyz1.set_coordinates((0, 0, 0)) xyz2.set_coordinates((0, 0, 0)) linear = IMP.core.Linear(0, 0.0) linear.set_slope(0.01) dps2 = IMP.core.DistancePairScore(linear) lr = IMP.core.PairRestraint(dps2, IMP.ParticlePair(p1, p2)) maxdist = 40.0 npoints = 100 dists = [] scores = [] for i in range(npoints): xyz2.set_coordinates( IMP.algebra.Vector3D(maxdist / npoints * float(i), 0.0, 0.0)) dist = IMP.core.get_distance(xyz1, xyz2) score = lr.unprotected_evaluate(None) print dist, score
def __init__(self, root, data, extra_sel={'atom_type': IMP.atom.AtomType('NZ')}, length=10.0, slope=0.01, nstates=None, label='', max_dist=None, nuisances_are_optimized=True, sigma_init=5.0, psi_init=0.01, one_psi=True, create_nz=False): """Experimental ATOMIC XL restraint. Provide selections for the particles to restrain. Automatically creates one "sigma" per crosslinked residue and one "psis" per pair. Other nuisance options are available. \note Will return an error if the data+extra_sel don't specify two particles per XL pair. @param root The root hierarchy on which you'll do selection @param data CrossLinkData object @param extra_sel Additional selections to add to each data point. Defaults to: {'atom_type':IMP.atom.AtomType('NZ')} @param length The XL linker length @param nstates The number of states to model. Defaults to the number of states in root. @param label The output label for the restraint @param nuisances_are_optimized Whether to optimize nuisances @param sigma_init The initial value for all the sigmas @param psi_init The initial value for all the psis @param one_psi Use a single psi for all restraints (if False, creates one per XL) @param create_nz Coarse-graining hack - add 'NZ' atoms to every XL'd lysine """ self.mdl = root.get_model() self.root = root self.weight = 1.0 self.label = label self.length = length self.nuis_opt = nuisances_are_optimized self.nstates = nstates if nstates is None: self.nstates = len(IMP.atom.get_by_type(root, IMP.atom.STATE_TYPE)) elif nstates != len(IMP.atom.get_by_type(root, IMP.atom.STATE_TYPE)): print( "Warning: nstates is not the same as the number of states in root" ) self.rs = IMP.RestraintSet(self.mdl, 'xlrestr') self.rs_nuis = IMP.RestraintSet(self.mdl, 'prior_nuis') self.particles = defaultdict(set) self.one_psi = one_psi self.create_nz = create_nz if one_psi: print('creating a single psi for all XLs') else: print('creating one psi for each XL') #### Setup two sigmas based on promiscuity of the residue ### psi_min_nuis = 1e-7 psi_max_nuis = 0.4999999 psi_min_prior = 0.01 psi_max_prior = 0.49 sigma_min_nuis = 1e-7 sigma_max_nuis = 100.1 sigma_min_prior = 1e-3 sigma_max_prior = 100.0 ''' sig_threshold=4 self.sig_low = setup_nuisance(self.mdl,self.rs_nuis,init_val=sigma_init,min_val=1.0, max_val=100.0,is_opt=self.nuis_opt) self.sig_high = setup_nuisance(self.mdl,self.rs_nuis,init_val=sigma_init,min_val=1.0, max_val=100.0,is_opt=self.nuis_opt) ''' self.sigma = setup_nuisance(self.mdl, self.rs_nuis, init_val=sigma_init, min_val_nuis=sigma_min_nuis, max_val_nuis=sigma_max_nuis, min_val_prior=sigma_min_prior, max_val_prior=sigma_max_prior, is_opt=self.nuis_opt, add_jeff=False) if one_psi: self.psi = setup_nuisance(self.mdl, self.rs_nuis, init_val=psi_init, min_val_nuis=psi_min_nuis, max_val_nuis=psi_max_nuis, min_val_prior=psi_min_prior, max_val_prior=psi_max_prior, is_opt=self.nuis_opt, add_jeff=True) else: self.psis = {} for unique_id in data: self.psis[unique_id] = setup_nuisance( self.mdl, self.rs_nuis, init_val=psi_init, min_val_nuis=psi_min_nuis, max_val_nuis=psi_max_nuis, min_val_prior=psi_min_prior, max_val_prior=psi_max_prior, is_opt=self.nuis_opt, add_jeff=True) ### first read ahead to get the number of XL's per residue #num_xls_per_res=defaultdict(int) #for unique_id in data: # for nstate in range(self.nstates): # for xl in data[unique_id]: # num_xls_per_res[str(xl.r1)]+=1 # num_xls_per_res[str(xl.r2)]+=1 ### optionally create NZs, add to hierarchy, and create bond/angle restraints # consider moving this elsewhere (but it has to be done before setting up XL restraint!) self.bonded_pairs = [] if self.create_nz: to_add = set() kappa = 1.0 self.rset_bonds = IMP.RestraintSet(self.mdl, 'Lysine_Sidechain_bonds') self.rset_angles = IMP.RestraintSet(self.mdl, 'Lysine_Sidechain_angles') for nstate in range(self.nstates): for unique_id in data: for xl in data[unique_id]: xl_pairs = xl.get_selection(root, state_index=nstate) for pp in xl_pairs: to_add.add(pp[0]) to_add.add(pp[1]) for ca in to_add: x0 = IMP.core.XYZ(ca).get_coordinates() res = IMP.atom.get_residue(IMP.atom.Atom(ca)) frag = res.get_parent() #print('ca',ca) #print('res',res) #print('frag',frag) #IMP.atom.show_molecular_hierarchy(frag) nz = IMP.Particle(self.mdl) a = IMP.atom.Atom.setup_particle(nz, IMP.atom.AtomType('NZ')) IMP.core.XYZR.setup_particle(nz, IMP.algebra.Sphere3D(x0, 1.85)) res.add_child(a) # bond restraint h = IMP.core.HarmonicUpperBound(6.0, kappa) dps = IMP.core.DistancePairScore(h) pr = IMP.core.PairRestraint(dps, IMP.ParticlePair(ca, nz)) self.bonded_pairs.append([ca, nz]) self.rset_bonds.add_restraint(pr) # angle restraints hus = IMP.core.Harmonic(2.09, kappa) sel_pre = IMP.atom.Selection(frag, residue_index=res.get_index() - 1).get_selected_particles() sel_post = IMP.atom.Selection(frag, residue_index=res.get_index() + 1).get_selected_particles() if len(sel_pre) > 1 or len(sel_post) > 1: print("SOMETHING WRONG WITH THIS FRAG") print('ca', ca) print('res', res) print('frag', frag) IMP.atom.show_molecular_hierarchy(frag) exit() if len(sel_pre) == 0: nter = True else: nter = False ca_pre = sel_pre[0] if len(sel_post) == 0: cter = True else: cter = False ca_post = sel_post[0] #print('nter?',nter,'cter?',cter) if nter and not cter: ar_post = IMP.core.AngleRestraint(hus, ca_post, ca, nz) self.rset_angles.add_restraint(ar_post) elif cter and not nter: ar_pre = IMP.core.AngleRestraint(hus, ca_pre, ca, nz) self.rset_angles.add_restraint(ar_pre) elif nter and cter: continue else: hus2 = IMP.core.Harmonic(0, kappa) idr = IMP.core.DihedralRestraint(hus2, ca, ca_pre, ca_post, nz) self.rset_angles.add_restraint(idr) ### create all the XLs xlrs = [] for unique_id in data: # create restraint for this data point if one_psi: psip = self.psi.get_particle_index() else: psip = self.psis[unique_id].get_particle_index() r = IMP.isd.AtomicCrossLinkMSRestraint(self.mdl, self.length, psip, slope, True) xlrs.append(r) num_contributions = 0 # add a contribution for each XL ambiguity option within each state for nstate in range(self.nstates): for xl in data[unique_id]: xl_pairs = xl.get_selection(root, state_index=nstate, **extra_sel) # figure out sig1 and sig2 based on num XLs ''' num1=num_xls_per_res[str(xl.r1)] num2=num_xls_per_res[str(xl.r2)] if num1<sig_threshold: sig1=self.sig_low else: sig1=self.sig_high if num2<sig_threshold: sig2=self.sig_low else: sig2=self.sig_high ''' sig1 = self.sigma sig2 = self.sigma # add each copy contribution to restraint for p1, p2 in xl_pairs: self.particles[nstate] |= set([p1, p2]) if max_dist is not None: dist = IMP.core.get_distance( IMP.core.XYZ(p1), IMP.core.XYZ(p2)) if dist > max_dist: continue r.add_contribution( [p1.get_index(), p2.get_index()], [ sig1.get_particle_index(), sig2.get_particle_index() ]) num_contributions += 1 if num_contributions == 0: raise RestraintSetupError("No contributions!") print('created', len(xlrs), 'XL restraints') self.rs = IMP.isd.LogWrapper(xlrs, self.weight)
# Each girl has a selection of dresses selection = random.sample(prices, n_dresses) allowed_states_indices = [prices.index(price) for price in selection] print(p.get_name(), "prices selected", selection, "indices", allowed_states_indices) list_states_table = IMP.domino.ListSubsetFilterTable(states_table) list_states_table.set_allowed_states(p, allowed_states_indices) sampler.add_subset_filter_table(list_states_table) # create restraints rs = [] for z in range(n_edges): # pair of friends i = random.randrange(0, n_girls) j = random.randrange(0, n_girls) friends = IMP.ParticlePair(girls[i], girls[j]) # restraint score = SumPricePairScore() rs.append(IMP.core.PairRestraint(model, score, friends)) # Exclusion states. Two girls can't have same dress ft = IMP.domino.ExclusionSubsetFilterTable() ft.add_pair(friends) sampler.add_subset_filter_table(ft) sampler.set_restraints(rs) subset = states_table.get_subset() solutions = sampler.get_sample_assignments(subset) if len(solutions) == 0: print("There are no solutions to the problem") else: