Esempio n. 1
0
    def create(self,
               reference_state,
               alchemical_states,
               positions,
               displacement_sigma=None,
               mc_atoms=None,
               options=None,
               metadata=None):
        """
        Initialize a modified Hamiltonian exchange simulation object.

        Parameters
        ----------
        reference_state : ThermodynamicState
           reference state containing all thermodynamic parameters and reference System object'
        alchemical_states : list of AlchemicalState
           list of alchemical states (one per replica)
        positions : simtk.unit.Quantity of numpy natoms x 3 with units length
           positions (or a list of positions objects) for initial assignment of replicas (will be used in round-robin assignment)
        displacement_sigma : simtk.unit.Quantity with units distance
           size of displacement trial for Monte Carlo displacements, if specified (default: 1 nm)
        ligand_atoms : list of int, optional, default=None
           atoms to use for trial displacements for translational and orientational Monte Carlo trials, if specified (all atoms if None)
        options : dict, optional, default=None
           Optional dict to use for specifying simulation options. Provided keywords will be matched to object variables to replace defaults.
        metadata : dict, optional, default=None
           metadata to store in a 'metadata' group in store file

        """

        # If an empty set is specified for mc_atoms, set this to None.
        if mc_atoms is not None:
            if len(mc_atoms) == 0:
                mc_atoms = None

        # Store trial displacement magnitude and atoms to rotate in MC move.
        self.displacement_sigma = 1.0 * unit.nanometer
        if mc_atoms is not None:
            self.mc_atoms = np.array(mc_atoms)
            self.mc_displacement = True
            self.mc_rotation = True
        else:
            self.mc_atoms = None
            self.mc_displacement = False
            self.mc_rotation = False

        self.displacement_trials_accepted = 0  # number of MC displacement trials accepted
        self.rotation_trials_accepted = 0  # number of MC displacement trials accepted

        # Store reference system.
        self.reference_system = copy.deepcopy(reference_state.system)

        # TODO: Form metadata dict.

        # Initialize replica-exchange simlulation.
        states = list()
        for alchemical_state in alchemical_states:
            state = ThermodynamicState(system=self.reference_system,
                                       temperature=reference_state.temperature,
                                       pressure=reference_state.pressure)
            setattr(state, 'alchemical_state',
                    copy.deepcopy(alchemical_state))  # attach alchemical state
            states.append(state)

        # Initialize replica-exchange simlulation.
        ReplicaExchange.create(self,
                               states,
                               positions,
                               options=options,
                               metadata=metadata)

        # Override title.
        self.title = 'Alchemical Hamiltonian exchange simulation created using HamiltonianExchange class of repex.py on %s' % time.asctime(
            time.localtime())

        return
Esempio n. 2
0
    def create(self, reference_state, alchemical_states, positions, displacement_sigma=None, mc_atoms=None, options=None, metadata=None):
        """
        Initialize a modified Hamiltonian exchange simulation object.

        Parameters
        ----------
        reference_state : ThermodynamicState
           reference state containing all thermodynamic parameters and reference System object'
        alchemical_states : list of AlchemicalState
           list of alchemical states (one per replica)
        positions : simtk.unit.Quantity of numpy natoms x 3 with units length
           positions (or a list of positions objects) for initial assignment of replicas (will be used in round-robin assignment)
        displacement_sigma : simtk.unit.Quantity with units distance
           size of displacement trial for Monte Carlo displacements, if specified (default: 1 nm)
        ligand_atoms : list of int, optional, default=None
           atoms to use for trial displacements for translational and orientational Monte Carlo trials, if specified (all atoms if None)
        options : dict, optional, default=None
           Optional dict to use for specifying simulation options. Provided keywords will be matched to object variables to replace defaults.
        metadata : dict, optional, default=None
           metadata to store in a 'metadata' group in store file

        """

        # If an empty set is specified for mc_atoms, set this to None.
        if mc_atoms is not None:
            if len(mc_atoms) == 0:
                mc_atoms = None

        # Store trial displacement magnitude and atoms to rotate in MC move.
        self.displacement_sigma = 1.0 * unit.nanometer
        if mc_atoms is not None:
            self.mc_atoms = np.array(mc_atoms)
            self.mc_displacement = True
            self.mc_rotation = True
        else:
            self.mc_atoms = None
            self.mc_displacement = False
            self.mc_rotation = False

        self.displacement_trials_accepted = 0 # number of MC displacement trials accepted
        self.rotation_trials_accepted = 0 # number of MC displacement trials accepted

        # Store reference system.
        self.reference_system = copy.deepcopy(reference_state.system)

        # TODO: Form metadata dict.

        # Initialize replica-exchange simlulation.
        states = list()
        for alchemical_state in alchemical_states:
            state = ThermodynamicState(system=self.reference_system, temperature=reference_state.temperature, pressure=reference_state.pressure)
            setattr(state, 'alchemical_state', copy.deepcopy(alchemical_state)) # attach alchemical state
            states.append(state)

        # Initialize replica-exchange simlulation.
        ReplicaExchange.create(self, states, positions, options=options, metadata=metadata)

        # Override title.
        self.title = 'Alchemical Hamiltonian exchange simulation created using HamiltonianExchange class of repex.py on %s' % time.asctime(time.localtime())

        return