Esempio n. 1
0
 def refine(self, step_count, protocol = None):
     if len(self.path) == 2:
         self.initialize()
     self.initializePenalties()
     p = self.penalty()
     if not hasattr(self, 'best_path'):
         self.best_path = copy(self.path)
         self.best_penalty = p
     if len(self.path) == 2:
         return
     if protocol is not None:
         protocol = open(protocol, 'w')
     temperature = 3*p
     while 1:
         to_be_moved = randrange(1, len(self.path)-1)
         displacement = randomParticleVector(self.universe, 1.)
         displacement = self.path[to_be_moved].modeWeighting(displacement)
         magnitude = gaussian(0., 0.1*self.step_length)
         old = self.path[to_be_moved]
         new = old.moveBy(displacement, magnitude)
         self.path[to_be_moved] = new
         self.updatePenalties(to_be_moved)
         new_p = self.penalty()
         if new_p > p and N.exp((p-new_p)/temperature) > uniform(0., 1.):
             self.path[to_be_moved] = old
             self.updatePenalties(to_be_moved)
         else:
             p = new_p
             if p < self.best_penalty:
                 self.best_penalty = p
                 self.best_path = copy(self.path)
         if protocol is not None:
             protocol.write('%f\n' % p)
             protocol.flush()
         step_count = step_count - 1
         if step_count == 0:
             break
     if protocol is not None:
         protocol.close()
Esempio n. 2
0
"""Construct the system. A scaling factor of 0.1 for CalphaForceField was determined empirically for a C-phycocyanin dimer at 300K; it's value is expected to depend at least on the protein and the temperature, but the order of magnitude should be correct for mid-sized proteins."""

universe = InfiniteUniverse(CalphaForceField(2.5, 0.1))
universe.protein = Protein('insulin.pdb', model='calpha')

""" Set all masses to the same value since we don't want mass-weighted sampling"""
for atom in universe.atomList():
    atom.setMass(1.)

""" Calculate normal modes. Note that the normal modes are automatically scaled to their vibrational amplitudes at a given temperature"""
modes = NormalModes(universe, 300.*Units.K)

# Create trajectory
trajectory = Trajectory(universe, "insulin_backbone.nc", "w", "Monte-Carlo sampling for insulin backbone")

# Create the snapshot generator
snapshot = SnapshotGenerator(universe, actions = [TrajectoryOutput (trajectory, ["all"], 0, None, 1)])

""" Generate an ensemble of 100 configurations. The scaling factor for each mode is half the vibrational amplitude, which explains the factor 0.5."""

minimum = copy(universe.configuration())
for i in range(100):
    conf = minimum
    for j in range(6, len(modes)):
        conf = conf + gaussian(0., 0.5)*modes[j]
    universe.setConfiguration(conf)
    snapshot()

# time to close it
trajectory.close()
        return FFTSeries[:len(series)]/(len(series)-N.arange(len(series)))

    from MMTK.Random import gaussian
    from Scientific.Statistics import mean
    from Scientific.IO.ArrayIO import readArray
    from Gnuplot import plot
    from RandomArray import random
    dt = 1.
    t = dt*N.arange(500)
    if 0:
        data = N.sin(t) + N.cos(3.*t) + 0.1*(random(len(t))-0.5)
        data = data + 0.1j*(random(len(t))-0.5)
    if 0:
        data = [0.]
        for i in range(500+len(t)-1):
            data.append(mean(data[-500:]) + gaussian(0., 0.1))
        data = N.exp(1j*N.array(data[500:]))

    if 0:
        #data = readArray('~/scientific/Test/data')
        string = open('/users1/hinsen/scientific/Test/data').read()[4:]
        data = N.array(eval(string))
        data = data[:,0]
    model = AutoRegressiveModel(20, data, dt)
    print model.coeff
    print model.poles()
    c = model.correlation(200)
    cref = InterpolatingFunction((t,), AutoCorrelationFunction(data))[:200]
    m = model.memoryFunction(200)
    s = model.spectrum(N.arange(0., 5., 0.01))
    #plot(c.real, cref.real); plot(c.imag, cref.imag)
Esempio n. 4
0
        return FFTSeries[:len(series)] / (len(series) - N.arange(len(series)))

    from MMTK.Random import gaussian
    from Scientific.Statistics import mean
    from Scientific.IO.ArrayIO import readArray
    from Gnuplot import plot
    from RandomArray import random
    dt = 1.
    t = dt * N.arange(500)
    if 1:
        data = N.sin(t) + N.cos(3. * t) + 0.1 * (random(len(t)) - 0.5)
        data = data + 0.1j * (random(len(t)) - 0.5)
    if 0:
        data = [0.]
        for i in range(500 + len(t) - 1):
            data.append(mean(data[-500:]) + gaussian(0., 0.1))
        data = N.exp(1j * N.array(data[500:]))

    if 0:
        #data = readArray('~/scientific/Test/data')
        string = open('/users1/hinsen/scientific/Test/data').read()[4:]
        data = N.array(eval(string))
        data = data[:, 0]
    model = AutoRegressiveModel(20, data, dt)
    print model.coeff
    print model.poles()
    c = model.correlation(200)
    cref = InterpolatingFunction((t, ), AutoCorrelationFunction(data))[:200]
    m = model.memoryFunction(200)
    s = model.spectrum(N.arange(0., 5., 0.01))
    #plot(c.real, cref.real); plot(c.imag, cref.imag)
Esempio n. 5
0
# Set all masses to the same value, since we don't want
# mass-weighted sampling.
for atom in universe.atomList():
    atom.setMass(1.)

# Calculate normal modes. Note that the normal modes are automatically
# scaled to their vibrational amplitudes at a given temperature.
modes = NormalModes(universe, 300. * Units.K)

# Create trajectory
trajectory = Trajectory(universe, "insulin_backbone.nc", "w",
                        "Monte-Carlo sampling for insulin backbone")

# Create the snapshot generator
snapshot = SnapshotGenerator(
    universe, actions=[TrajectoryOutput(trajectory, ["all"], 0, None, 1)])

# Generate an ensemble of 100 configurations. The scaling factor for
# each mode is half the vibrational amplitude, which explains the
# factor 0.5.
minimum = copy(universe.configuration())
for i in range(100):
    conf = minimum
    for j in range(6, len(modes)):
        conf = conf + gaussian(0., 0.5) * modes[j]
    universe.setConfiguration(conf)
    snapshot()

# Close trajectory
trajectory.close()