15 import matplotlib.pyplot
31 def create_particle(m, radius = DEFAULT_RADIUS):
37 def create_linear_point_pair_score():
38 ''' slope*x + intercept for point distance '''
42 def create_harmonic_point_pair_score():
43 ''' 0.5*k*(x-mean)^2 for point distance '''
47 def create_linear_sphere_pair_score():
48 ''' slope*x + intercept for sphere distance '''
52 def create_harmonic_sphere_pair_score():
53 ''' 0.5*k*(x-mean)^2 for sphere distance '''
57 def create_model(pair_score):
59 particles = [create_particle(m)
for x
in range(2)]
62 return m, xyzrs, restraint
64 def plot_score(pair_score, caption,
65 xmin = -15.0, xmax = 15.0, xstep = 0.01):
67 Plots a pair_score between two particles, one particle
68 being at [0,0,0] and the other particle being at [x,0,0]
69 for x in the closed interval [xmin:xstep:xmax]
71 m, xyzrs, restraint = create_model(pair_score)
72 xyzrs[0].set_coordinates([0,0,0])
73 X = numpy.arange(xmin, xmax+0.1*xstep, xstep)
75 for i,x
in enumerate(X):
76 xyzrs[0].set_coordinates([x,0,0])
77 Y[i] = restraint.get_score()
79 print(
"Not showing plot; matplotlib is not installed "
80 "or could not be imported")
82 print(
"Not showing plot, as we are running test cases")
84 matplotlib.pyplot.plot(X,Y,
'-')
85 matplotlib.pyplot.title(caption)
86 matplotlib.pyplot.xlabel(
r"$X_2$ [$\AA$]")
87 matplotlib.pyplot.ylabel(
"Energy [$kcal \cdot mol^{-1}$]")
88 matplotlib.pyplot.gca().spines[
'bottom'].set_position((
'data', 0))
89 matplotlib.pyplot.show()
91 if __name__ ==
"__main__":
93 linear_str =
"{:.1f}*(dist-{:.1f})".format(LINEAR_SLOPE, LINEAR_OFFSET)
94 harmonic_str =
"{:.1f}*(dist-{:.1f})^2".format(HARMONIC_K, HARMONIC_MEAN)
95 plot_score(create_linear_point_pair_score(),
96 caption=
"Linear point distance\n{}"
98 plot_score(create_linear_sphere_pair_score(),
99 caption=
"Linear sphere distance (R={:.1f} A)\n{}"
100 .format(DEFAULT_RADIUS, linear_str))
101 plot_score(create_harmonic_point_pair_score(),
102 caption=
"Harmonic point distance\n{}"
103 .format(harmonic_str))
104 plot_score(create_harmonic_sphere_pair_score(),
105 caption=
"Harmonic sphere distance (R={:.1f} A)\n{}"
106 .format(DEFAULT_RADIUS, harmonic_str))
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
static XYZR setup_particle(Model *m, ParticleIndex pi)
A score on the distance between the surfaces of two spheres.
Class for storing model, its restraints, constraints, and particles.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Class to handle individual particles of a Model object.
Applies a PairScore to a Pair.
Harmonic function (symmetric about the mean)
A decorator for a particle with x,y,z coordinates and a radius.