2 from __future__
import print_function
10 class MyGetRestraint(object):
11 def __init__(self,rs):
13 def get_restraint_for_rmf(self):
17 """ Enable CHARMM force field """
22 enable_nonbonded=
True,
24 zone_nonbonded=
False):
25 """Setup the charmm restraint on a selection. Expecting atoms.
26 @param root The node at which to apply the restraint
27 @param ff_temp The temperature of the force field
28 @param zone_ps Create a zone around this set of particles
29 Automatically includes the entire residue (incl. backbone)
30 @param zone_size The size for looking for neighbor residues
31 @param enable_nonbonded Allow the repulsive restraint
32 @param enable_bonded Allow the bonded restraint
33 @param zone_nonbonded EXPERIMENTAL: exclude from nonbonded all sidechains that aren't in zone!
36 kB = (1.381 * 6.02214) / 4184.0
38 self.mdl = root.get_model()
40 self.nonbonded_rs =
IMP.RestraintSet(self.mdl, 1.0 / (kB * ff_temp),
'NONBONDED')
47 topology = ff.create_topology(root)
48 topology.apply_default_patches()
49 topology.setup_hierarchy(root)
50 if zone_ps
is not None:
56 exclude_backbone=
False)
64 self.bonds_rs.add_restraint(r)
66 ff.add_well_depths(root)
71 if (zone_ps
is not None)
and zone_nonbonded:
72 print(
'stereochemistry: zone_nonbonded is True')
74 backbone_types=[
'C',
'N',
'CB',
'O']
76 for n
in backbone_types])
77 backbone_atoms = sel.get_selected_particles()
84 exclude_backbone=
True)
94 self.nbl.add_pair_filter(r.get_full_pair_filter())
97 self.nonbonded_rs.add_restraint(pr)
99 print(
'CHARMM is set up')
101 def set_label(self, label):
103 self.bonds_rs.set_name(self.bonds_rs.get_name()+label)
104 self.nonbonded_rs.set_name(self.nonbonded_rs.get_name()+label)
106 def add_to_model(self):
107 self.mdl.add_restraint(self.bonds_rs)
108 self.mdl.add_restraint(self.nonbonded_rs)
110 def get_restraints(self):
111 return [self.bonds_rs,self.nonbonded_rs]
113 def get_restraint(self):
116 def get_close_pair_container(self):
122 def set_weight(self, weight):
124 self.bonds_rs.set_weight(weight)
125 self.nonbonded_rs.set_weight(weight)
126 print(
'CHARMM: weight is',self.weight)
128 def get_output(self):
131 bonds_score = self.weight * self.bonds_rs.unprotected_evaluate(
None)
132 nonbonded_score = self.weight * self.nonbonded_rs.unprotected_evaluate(
None)
133 score=bonds_score+nonbonded_score
134 output[
"_TotalScore"] = str(score)
135 output[
"CHARMM_BONDS"+str(self.label)] = str(bonds_score)
136 output[
"CHARMM_NONBONDED"+str(self.label)] = str(nonbonded_score)
139 class ElasticNetworkRestraint(object):
146 """ Add harmonic restraints between all pairs below a specified distance
147 @param root Root hierarchy for applying selections
148 @param subsequence A PMI Subsequence class
149 @param strength The elastic bond strength
150 @param dist_cutoff Create bonds when below this distance
151 \note any additional keyword arguments are passed to the Selection
152 E.g. you could pass atom_type=IMP.atom.AtomType("CA")c
154 self.mdl = root.get_model()
159 if subsequence
is not None:
160 self.ps = subsequence.get_selection(root,**kwargs).get_selected_particles()
164 print(
'ERROR: Did not select any particles!')
168 print(
'created elastic network',self.label,
'with',self.rs.get_number_of_restraints(),
'restraints')
170 def set_label(self, label):
172 self.rs.set_name(label)
173 for r
in self.rs.get_restraints():
179 def add_to_model(self):
180 self.mdl.add_restraint(self.rs)
182 def get_restraint(self):
185 def set_weight(self, weight):
187 self.rs.set_weight(weight)
189 def get_excluded_pairs(self):
190 return self.pairslist
192 def get_restraints_for_rmf(self):
193 return [MyGetRestraint(self.rs)]
195 def get_output(self):
198 score = self.weight * self.rs.unprotected_evaluate(
None)
199 output[
"ElasticNetworkRestraint_" + self.label] = str(score)
200 output[
"_TotalScore"] = str(score)
203 class SymmetryRestraint(object):
210 """ Add harmonic restraints to the mean positions between multiple selections.
211 @param root Root hierarchy for applying selections
212 @param symmetry_transforms Transforms moving each selection to the first selection
213 @param selection_dicts Selection kwargs for each symmetry unit
214 @param extra_sel Additional selection arguments (e.g., CA only!)
215 @param strength The elastic bond strength
217 \note the length of symmetry_transforms should be one more than the length of selection_dicts
218 Because all transforms are WRT the first selection
220 self.mdl = root.get_model()
225 if len(selection_dicts)!=len(symmetry_transforms)+1:
226 print(
'Error: There should be one more symmetry transform than selection dict')
229 sel0 = hierarchy_tools.combine_dicts(selection_dicts[0],extra_sel)
232 print(
"Error: did not select any particles!")
234 for sdict,trans
in zip(selection_dicts[1:],symmetry_transforms):
235 sel = hierarchy_tools.combine_dicts(sdict,extra_sel)
237 if len(ps0)!=len(ps):
238 print(
"Error: did not select the same number of particles!")
241 for p0,p1
in zip(ps0,ps):
243 self.rs.add_restraint(r)
245 print(
'created symmetry network with',self.rs.get_number_of_restraints(),
'restraints')
247 def set_label(self, label):
249 self.rs.set_name(label)
250 for r
in self.rs.get_restraints():
253 def add_to_model(self):
254 self.mdl.add_restraint(self.rs)
256 def get_restraint(self):
259 def set_weight(self, weight):
261 self.rs.set_weight(weight)
263 def get_excluded_pairs(self):
264 return self.pairslist
266 def get_output(self):
269 score = self.weight * self.rs.unprotected_evaluate(
None)
270 output[
"SymmetryRestraint_" + self.label] = str(score)
271 output[
"_TotalScore"] = str(score)
275 """ Add bonds, angles, and dihedrals for a CA-only model """
276 def __init__(self,root,
CHARMMParameters * get_heavy_atom_CHARMM_parameters()
Enforce CHARMM stereochemistry on the given Hierarchy.
def __init__
Setup the charmm restraint on a selection.
def get_particles_within_zone
Utility to retrieve particles from a hierarchy within a zone around a set of ps.
Return all close unordered pairs of particles taken from the SingletonContainer.
Return all close ordered pairs of particles taken from the two SingletonContainers.
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
Object used to hold a set of restraints.
Enable CHARMM force field.
RestraintSet * create_elastic_network(const Particles &ps, Float dist_cutoff, Float strength)
Create an elastic network restraint set.
Add bonds, angles, and dihedrals for a CA-only model.
Store a list of ParticleIndexes.
Basic functionality that is expected to be used by a wide variety of IMP users.
Applies a PairScore to a Pair.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
Select hierarchy particles identified by the biological name.
Applies a PairScore to each Pair in a list.
A repulsive potential on the distance between two atoms.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...
Harmonic function (symmetric about the mean)