Пример #1
0
            move *= self.max_atom_move/mmax
        return move

    def _make_move(self, current, move):
        if self.mol.constraints:
            # TODO: get constraint forces from lagrange multipliers and use them to check for convergence
            self._sync_positions(current)
            prev = self.mol.positions.copy()
            self._sync_positions(current+move)

            mdt.geom.shake_positions(self.mol, prev)
            return self._coords_to_vector(self.mol.positions)
        else:
            return current + move

    def _constraint_convergence(self, pos, lastpos, energygrad):
        """ Test for force-based convergence after projecting out constraint forces

        Until the shake method starts explicitly storing constraint forces, we calculate this
        direction as the SHAKE-adjusted displacement vector from the current descent step
        """
        direction = mdt.mathutils.normalized((pos - lastpos).flatten())
        proj_grad = energygrad.dot(direction)
        return abs(proj_grad) < self.force_tolerance


gradient_descent = GradientDescent._as_function('gradient_descent')
exports(gradient_descent)
toplevel(gradient_descent)

Пример #2
0
        descender.run()
        if descender.current_step >= self.nsteps:
            self.traj = descender.traj
            return

        # Finally, use a quadratic method to converge the optimization
        kwargs = dict(_restart_from=descender.current_step,
                      _restart_energy=descender._initial_energy)
        kwargs['frame_interval'] = self.kwargs.get('frame_interval',
                                                   descender.frame_interval)
        spmin = self._make_quadratic_method(kwargs)
        spmin.current_step = descender.current_step
        spmin.run()
        self.traj = descender.traj + spmin.traj
        self.current_step = spmin.current_step

    def _make_quadratic_method(self, kwargs=None):
        if kwargs is None: kwargs = {}
        kw = self.kwargs.copy()
        kw.update(kwargs)
        if self.mol.constraints:
            spmin = SequentialLeastSquares(*self.args, **kw)
        else:
            spmin = BFGS(*self.args, **kw)
        return spmin


minimize = SmartMin._as_function('minimize')
exports(minimize)
toplevel(minimize)
Пример #3
0
        self.__foundmin = val

    @property
    def currentstep(self):
        if self._descent:
            return self._descent.currentstep
        elif self._spmin:
            return self._spmin.currentstep
        else:
            return self._currentstep

    @currentstep.setter
    def currentstep(self, val):
        self._currentstep = val

    def _make_quadratic_method(self, kwargs=None):
        if kwargs is None: kwargs = {}
        kw = self.kwargs.copy()
        kw.update(kwargs)
        if self.mol.constraints:
            spmin = SequentialLeastSquares(*self.args, **kw)
        else:
            spmin = BFGS(*self.args, **kw)
        return spmin


minimize = SmartMin._as_function('minimize')
exports(minimize)
toplevel(minimize)

Пример #4
0
        if mmax > self.max_atom_move:  # rescale the move
            move *= self.max_atom_move / mmax
        return move

    def _make_move(self, current, move):
        if self.mol.constraints:
            # TODO: get constraint forces from lagrange multipliers and use them to check for convergence
            self._sync_positions(current)
            prev = self.mol.positions.copy()
            self._sync_positions(current + move)

            mdt.geom.shake_positions(self.mol, prev)
            return self._coords_to_vector(self.mol.positions)
        else:
            return current + move

    def _constraint_convergence(self, pos, lastpos, energygrad):
        """ Test for force-based convergence after projecting out constraint forces

        Until the shake method starts explicitly storing constraint forces, we calculate this
        direction as the SHAKE-adjusted displacement vector from the current descent step
        """
        direction = mdt.mathutils.normalized((pos - lastpos).flatten())
        proj_grad = energygrad.dot(direction)
        return abs(proj_grad) < self.force_tolerance


gradient_descent = GradientDescent._as_function('gradient_descent')
exports(gradient_descent)
toplevel(gradient_descent)
Пример #5
0
            self._sync_positions(v)
            return const.error().defunits_value()

        def jac(v):
            self._sync_positions(v)
            return const.gradient().defunits_value().reshape(self.mol.num_atoms*3)

        return fun, jac


@exports
class BFGS(ScipyMinimizer):
    _METHOD_NAME = 'bfgs'
    _TAKES_GTOL = True


bfgs = BFGS._as_function('bfgs')
exports(bfgs)
toplevel(bfgs)


@exports
class SequentialLeastSquares(ScipyMinimizer):
    _METHOD_NAME = 'SLSQP'
    _TAKES_FTOL = True


sequential_least_squares = SequentialLeastSquares._as_function('sequential_least_squares')
exports(sequential_least_squares)
toplevel(sequential_least_squares)
                          velocities=inpcrd.velocities)
    return mol


if force_remote:

    def amber_to_mol(prmtop_file, inpcrd_file):
        if not isinstance(prmtop_file, pyccc.FileContainer):
            prmtop_file = pyccc.LocalFile(prmtop_file)
        if not isinstance(inpcrd_file, pyccc.FileContainer):
            inpcrd_file = pyccc.LocalFile(inpcrd_file)
        return _amber_to_mol(prmtop_file, inpcrd_file)
else:
    amber_to_mol = _amber_to_mol

exports(amber_to_mol)


@exports
def topology_to_mol(topo,
                    name=None,
                    positions=None,
                    velocities=None,
                    assign_bond_orders=True):
    """ Convert an OpenMM topology object into an MDT molecule.

    Args:
        topo (simtk.openmm.app.topology.Topology): topology to convert
        name (str): name to assign to molecule
        positions (list): simtk list of atomic positions
        velocities (list): simtk list of atomic velocities