Ejemplo n.º 1
0
class VelocityVerlet(MolecularDynamics):
    
    """
    VelocityVerlet(self, mol, pot,  deltat, nstep, restart, check_mdstop_dispersion, tlim)
        ** This is performing QM or MM MD-Simulation.  
            
            mol => Molecular instance. Refer to the Molecule.py 
            pot => Potential instance. Refer to the Potential.py 
            deltat => time step 
            nstep => step number  
            restart => whether md starts in the middle. default is False 
                       if restart is True, the initial condition is loaded from the restart file 
                       and the output files are written continuously. 
            check_mdstop_dispersion => when atoms are widely dispersed, md is terminated.
                                        default is False 
            tlim => set the time when md is finished. 
                    default is inf. Usually, the run of md is controlled by nstep.  
    """
    
    def __init__(self, mol, pot, dt, nstep, restart=False, check_mdstop_dispersion = False,\
                 limit_dispersion = 20.0, tlim = float('inf')):
        MolecularDynamics.__init__(self, mol, pot, dt, nstep, restart, check_mdstop_dispersion, limit_dispersion, tlim)
        if self.pot.get_check_pbc: self.mol.set_positions(self.pot.get_pbc_adjusted(self.mol.get_positions())) 
        self.count = 0 
        self.nrange = self.pot.get_nrange()
        self.setup_output() 
            
    def setup_output(self):
        self.woutp = WriteOutputMD()
        self.woutp.start(self)
        if self.restart: self.woutp.restart(self)

    def run(self):
        #this is the potential energy caluculation at the initial point 
        self.pot.calc() 
        
        #this is for logging at the initial point 
        self.woutp.logging(self)  

        # loop for MD 
        for _ in xrange(self.nstep):
            self.step() 
            self.count += 1
            self.woutp.logging(self)
            self.mdstop_time_trans()
            if self.mdstop_time_trans(): break
            if self.check_mdstop_dispersion and self.mdstop_atom_dispersion(): break
        self.woutp.finalize(self)
 
    def step(self):
        accelerations_save =  self.mol.get_accelerations()
        positions = self.mol.get_positions() + \
                self.mol.get_velocities() *  self.dt + 0.5 * \
                accelerations_save * self.dt * self.dt
        if self.pot.get_check_pbc(): self.mol.set_positions(self.pot.get_pbc_adjusted(positions)) 
        else:  self.mol.set_positions(positions) 
        self.pot.calc() 
        self.mol.set_velocities(self.mol.get_velocities() + \
                0.5 * (self.mol.get_accelerations() + \
                accelerations_save) * self.dt)
        self.elaptime += self.dt 
Ejemplo n.º 2
0
 def setup_output(self):
     self.woutp = WriteOutputMD()
     self.woutp.start(self)
     if self.restart: self.woutp.restart(self)
Ejemplo n.º 3
0
 def setup_output(self):
     self.woutp = WriteOutputMD()
     self.woutp.start(self)
     if self.restart: self.woutp.restart(self)
Ejemplo n.º 4
0
class VelocityVerlet(MolecularDynamics):
    """
    VelocityVerlet(self, mol, pot,  deltat, nstep, restart, check_mdstop_dispersion, tlim)
        ** This is performing QM or MM MD-Simulation.  
            
            mol => Molecular instance. Refer to the Molecule.py 
            pot => Potential instance. Refer to the Potential.py 
            deltat => time step 
            nstep => step number  
            restart => whether md starts in the middle. default is False 
                       if restart is True, the initial condition is loaded from the restart file 
                       and the output files are written continuously. 
            check_mdstop_dispersion => when atoms are widely dispersed, md is terminated.
                                        default is False 
            tlim => set the time when md is finished. 
                    default is inf. Usually, the run of md is controlled by nstep.  
    """

    def __init__(self, mol, pot, dt, nstep, restart=False, check_mdstop_dispersion = False,\
                 limit_dispersion = 20.0, tlim = float('inf')):
        MolecularDynamics.__init__(self, mol, pot, dt, nstep, restart,
                                   check_mdstop_dispersion, limit_dispersion,
                                   tlim)
        if self.pot.get_check_pbc:
            self.mol.set_positions(
                self.pot.get_pbc_adjusted(self.mol.get_positions()))
        self.count = 0
        self.nrange = self.pot.get_nrange()
        self.setup_output()

    def setup_output(self):
        self.woutp = WriteOutputMD()
        self.woutp.start(self)
        if self.restart: self.woutp.restart(self)

    def run(self):
        #this is the potential energy caluculation at the initial point
        self.pot.calc()

        #this is for logging at the initial point
        self.woutp.logging(self)

        # loop for MD
        for _ in xrange(self.nstep):
            self.step()
            self.count += 1
            self.woutp.logging(self)
            self.mdstop_time_trans()
            if self.mdstop_time_trans(): break
            if self.check_mdstop_dispersion and self.mdstop_atom_dispersion():
                break
        self.woutp.finalize(self)

    def step(self):
        accelerations_save = self.mol.get_accelerations()
        positions = self.mol.get_positions() + \
                self.mol.get_velocities() *  self.dt + 0.5 * \
                accelerations_save * self.dt * self.dt
        if self.pot.get_check_pbc():
            self.mol.set_positions(self.pot.get_pbc_adjusted(positions))
        else:
            self.mol.set_positions(positions)
        self.pot.calc()
        self.mol.set_velocities(self.mol.get_velocities() + \
                0.5 * (self.mol.get_accelerations() + \
                accelerations_save) * self.dt)
        self.elaptime += self.dt