Пример #1
0
    def calculate(self, atoms):
        self.positions = atoms.get_positions()
        pos = self.positions[:]
        scmepos = self.positions[:]
        truepos = pos[:]
        self.cell = atoms.get_cell()
        cell = self.cell

        numatoms = self.numatoms
        nummols = self.molnum

        # Atomwise  MIC PBCs needed for SCME
        n = np.zeros(np.shape(scmepos))
        c_mid = cell.diagonal() * 0.5
        n = np.rint((c_mid - pos) / cell.diagonal())
        scmepos += n * cell.diagonal()

        scme_atoms = atoms[:]
        scme_atoms.set_positions(scmepos)

        # Convert to scme coordinates
        scme_atoms = self.ase_to_scme(scme_atoms)
        scme_coords = scme_atoms.get_positions()
        scme_coords = scme_coords.transpose()

        # Call SCME
        # with shape tests:
        eF = np.reshape(self.eF, np.shape(self.eF), order="F")
        defield = np.reshape(self.defield, np.shape(self.defield), order="F")
        # print np.shape(defield)
        # eQM = np.zeros([3,nummols])
        testin = np.zeros([3, 3, nummols])

        testin = testin.reshape(3, 3, nummols, order="F")
        ff, epot, et, qpole = scme.main(scme_coords, cell.diagonal(), eF, defield)

        # CONVERT UNITS HERE! 1D = 0.20819434 e*Ang
        # SCME forces: Debye^2/Ang^3 ... which explains
        # convFactor = 14.39975841d0 / 4.803206799d0**2
        # and Elvars 1/4.8 = 0.208 ish ...

        # f = np.reshape(ff,[numatoms,3],order='F')
        f = np.reshape(ff, [numatoms, 3])
        # testout = testout.reshape(nummols,3,3,order='F')

        # Convert force array back to ase coordinates
        aseforces = self.f_scme_to_ase(f)

        # H's get Ey and Ez ... HACKING
        et = et.transpose()  # F-> P
        # et = np.reshape(et,[numatoms])
        # CHECK THIS PLEASE! WHERES THE REINDEXING?

        # update atoms with  the new charges
        self.dipoles = et.reshape(nummols, 3)
        self.qpoles = qpole
        self.atoms = atoms
        self.forces = aseforces
        self.energy = epot
Пример #2
0
    def calculate(self,atoms):
        self.positions = atoms.get_positions()
        pos = self.positions[:]
        scmepos = self.positions[:]
        truepos = pos[:]
        self.cell = atoms.get_cell()
        cell = self.cell
        
        numatoms = self.numatoms
        nummols = self.molnum        

        # Atomwise  MIC PBCs needed for SCME
        n = np.zeros(np.shape(scmepos)) 
        c_mid = cell.diagonal() * 0.5
        n = np.rint((c_mid - pos) / cell.diagonal())
        scmepos += n * cell.diagonal()
 
        scme_atoms = atoms[:]
        scme_atoms.set_positions(scmepos)
        
        # Convert to scme coordinates
        scme_atoms = self.ase_to_scme(scme_atoms)
        scme_coords = scme_atoms.get_positions()
        scme_coords = scme_coords.transpose()
        
        # Call SCME
        # with shape tests:
        eF = np.reshape(self.eF, np.shape(self.eF), order='F')
        deF = np.reshape(self.deF, np.shape(self.deF), order='F')
        #print np.shape(deF)
        #eQM = np.zeros([3,nummols])
        testin = np.zeros([3,3,nummols])
        testin = testin.reshape(3,3,nummols,order='F')
        eF = -1* eF / unit.Debye
        deF = -1* deF / unit.Debye 
        ff,epot,eT,dipole,qpole = scme.main(scme_coords,cell.diagonal(),eF,deF)
        # also get eT out: total field.
        #f = np.reshape(ff,[numatoms,3],order='F')
        f = np.reshape(ff,[numatoms,3])
        #testout = testout.reshape(nummols,3,3,order='F')
        # Convert force array back to ase coordinates
        aseforces = self.f_scme_to_ase(f)
        dipole = -1 * dipole*unit.Debye # go back to ase units
        dipole = dipole.transpose() # F-> P     
        eT = eT * unit.Debye
        eT = eT.transpose() # F-> P     

        # update calc and atoms
        self.dipoles = dipole.reshape(nummols, 3)
        #self.qpoles  = qpole NO QPOLES RIGHT NOW PLEASE
        self.qpoles  = np.zeros(np.shape(qpole))
        self.atoms = atoms 
        self.forces = aseforces
        self.energy = epot 
        self.eT = eT