Esempio n. 1
0
    def __init__(self,
                 potential: potentialCls = harmonicOscillatorPotential(),
                 sampler: samplerCls = metropolisMonteCarloIntegrator(),
                 conditions: Iterable[conditionCls] = None,
                 temperature: Number = 298.0,
                 start_position: (Iterable[Number] or Number) = None,
                 mass: Number = 1,
                 verbose: bool = True) -> NoReturn:
        """
            The system class is wrapping all components needed for a simulation.
            It can be used as the control unit for executing a simulation (simulate) and also to manage the generated data or input data.

        Parameters
        ----------
        potential : _potentialCls
            gives the potential function to be explored/sampled
        sampler : _samplerCls
            gives the method of choice to sample/explore the potential function
        conditions : Iterable[_conditionCls], optional
            apply the given conditions to the systems in a preset (tau) step iteration
        temperature : float, optional
            temperature of the system
        start_position : float, optional
            starting position of the system during the simulation
        mass : float, optional
            mass of the single particle
        verbose : bool, optional
            I can tell you a long iterative story...
        """

        ################################
        # Declare Attributes
        #################################

        ##Physical parameters
        self.nParticles = 1  # FUTURE: adapt it to be multiple particles
        self._mass = mass  # for one particle systems!!!!
        self._temperature = temperature

        # Output
        self._currentState = self.state(
            **{key: np.nan
               for key in self.state.__dict__["_fields"]})
        self._trajectory = []

        # tmpvars - private:
        self._currentTotE: (Number) = np.nan
        self._currentTotPot: (Number) = np.nan
        self._currentTotKin: (Number) = np.nan
        self._currentPosition: (Number or Iterable[Number]) = np.nan
        self._currentVelocities: (Number or Iterable[Number]) = np.nan
        self._currentForce: (Number or Iterable[Number]) = np.nan
        self._currentTemperature: (Number or Iterable[Number]) = np.nan

        # BUILD System
        ## Fundamental Parts:
        self._potential = potential
        self._integrator = sampler

        if (conditions is None):
            self._conditions = []
        else:
            self._conditions = conditions

        ## set dim
        if (potential.constants[potential.nDimensions] > 0):
            self.nDimensions = potential.constants[potential.nDimensions]
        else:
            raise IOError(
                "Could not estimate the disered Dimensionality as potential dim was <1 and no initial position was given."
            )

        ###is the potential a state dependent one? - needed for initial pos.
        if (hasattr(potential, "nStates")):
            self.nStates = potential.constants[potential.nStates]
        else:
            self.nstates = 1

        # PREPARE THE SYSTEM
        # Only init velocities, if the samplers uses them
        if (issubclass(sampler.__class__,
                       (newtonianSampler, langevinIntegrator))):
            init_velocity = True
        else:
            init_velocity = False

        self.initialise(withdraw_Traj=True,
                        init_position=True,
                        init_velocity=init_velocity,
                        set_initial_position=start_position)

        ##check if system should be coupled to conditions:
        # update for metadynamics simulation - local elevation bias is like a condition/potential hybrid.
        if (isinstance(self.potential, metadynamicsPotential1D)
                or isinstance(self.potential, metadynamicsPotential2D)):
            self._conditions.append(self.potential)

        for condition in self._conditions:
            if (not hasattr(condition, "system")):
                condition.couple_system(self)
            else:
                # warnings.warn("Decoupling system and coupling it again!")
                condition.couple_system(self)

            if (not hasattr(condition, "dt") and hasattr(self.sampler, "dt")):
                condition.dt = self.sampler.dt
            else:
                condition.dt = 1
        self.verbose = verbose
Esempio n. 2
0
 def test_1D_animation(self):
     sim = system(potential=harmonicOscillatorPotential(),
                  sampler=metropolisMonteCarloIntegrator())
     sim.simulate(100)
     animationSimulation.animation_trajectory(simulated_system=sim)
Esempio n. 3
0
 def test_1DPotential_V(self):
     plotPotentials.plot_1DPotential_Termoverlay(
         harmonicOscillatorPotential(), np.linspace(-10, 10, 100))
Esempio n. 4
0
 def test_static_sim_plots(self):
     sim = system(potential=harmonicOscillatorPotential(),
                  sampler=metropolisMonteCarloIntegrator())
     sim.simulate(100)
     plotSimulations.oneD_simulation_analysis_plot(sim)
Esempio n. 5
0
 def test_plot_1DPotential_dhdpos(self):
     plotPotentials.plot_1DPotential_dhdpos(harmonicOscillatorPotential(),
                                            np.linspace(-10, 10, 100))