def get_positions(self, coords='direct'): if self.direct_coords == True and coords[0].lower() == 'c': return oppvasp.direct_to_cartesian(self.positions, self.basis) elif self.direct_coords == False and coords[0].lower() == 'd': return oppvasp.cartesian_to_direct(self.positions, self.basis) else: return self.positions.copy()
def get_positions(self, coords = 'direct'): if self.direct_coords == True and coords[0].lower() == 'c': return oppvasp.direct_to_cartesian(self.positions, self.basis) elif self.direct_coords == False and coords[0].lower() == 'd': return oppvasp.cartesian_to_direct(self.positions, self.basis) else: return self.positions.copy()
def set_velocities(self, vel, coords): if type(vel).__name__ == 'ndarray': self._velocities = vel.copy() elif type(vel).__name__ == 'list': self._velocities = np.array(vel) elif type(vel).__name__ == 'NoneType': self._velocities = None else: print "Error: velocities must be a list or numpy array" self._velocities = None if self._velocities != None and coords[0] == 'c': self._velocities = cartesian_to_direct(self._velocities, self._cell)
def set_positions(self, pos, coords): """ Define atom positions using a (n,3) numpy array as the first argument. The function assumes cartesian coordinates by default, but a second argument can be added to indicate if the coordinates are direct ('d') or cartesian ('c'). """ if type(pos).__name__ == 'ndarray': self._positions = pos.copy() elif type(pos).__name__ == 'list': self._positions = np.array(pos) else: print "Error: positions must be a list or numpy array" if coords[0].lower() == 'c': self._positions = cartesian_to_direct(self._positions, self._cell)
def set_forces(self, forces, coords): """ Parameters: forces : (n,3) numpy array of forces on all atoms coords : 'direct' or 'cartesian' """ if type(forces).__name__ == 'ndarray': self._forces = forces.copy() elif type(forces).__name__ == 'list': self._forces = np.array(forces) elif type(forces).__name__ == 'NoneType': self._forces = None else: print "Error: forces must be a list or numpy array" self._forces = None if self._forces != None and coords[0] == 'c': self._forces = cartesian_to_direct(self._forces, self._cell)
def unwrap_pbc(self, init_pos=None, silent=False): """ Unwraps periodic boundary conditions (PBCs). Note that this procedure produces coordinates outside the unit cell. An initial set of coordinates must be specified as a Structure object, typically originating from a POSCAR file. Example: ---------- >>> pp = PoscarParser('POSCAR') >>> init_pos = pp.get_structure() >>> vp = VasprunParser('vasprun.xml') >>> fin_pos = vp.ionic_steps[-1].get_structure() >>> fin_pos = fin_pos.unwrap_pbc(init_pos) >>> print fin_pos - init_pos """ #if self.shape[0] != r0.shape[0]: # print "ERROR: Mismatch between number of atoms in initial and final structure! Aborting" # return # Convert initial coordinates to final basis: r0 = cartesian_to_direct(init_pos.get_positions('cart'), self._cell) r = self.get_positions('direct') n = r.shape[0] dr = r - r0 c = np.abs(np.array((dr - 1, dr, dr + 1))) diff = np.array([[np.argmin(c[:, i, j]) for j in range(3)] for i in range(n)]) - 1 # (-1,0,1) dr += diff if not silent and np.max(dr) > 0.1: print u"Warning: largest displacement of %.1f (direct units) is rather large..." % ( np.max(dr)) self.set_positions(r0 + dr, 'direct')
def unwrap_pbc(self, init_pos = None, silent = False): """ Unwraps periodic boundary conditions (PBCs). Note that this procedure produces coordinates outside the unit cell. An initial set of coordinates must be specified as a Structure object, typically originating from a POSCAR file. Example: ---------- >>> pp = PoscarParser('POSCAR') >>> init_pos = pp.get_structure() >>> vp = VasprunParser('vasprun.xml') >>> fin_pos = vp.ionic_steps[-1].get_structure() >>> fin_pos = fin_pos.unwrap_pbc(init_pos) >>> print fin_pos - init_pos """ #if self.shape[0] != r0.shape[0]: # print "ERROR: Mismatch between number of atoms in initial and final structure! Aborting" # return # Convert initial coordinates to final basis: r0 = cartesian_to_direct(init_pos.get_positions('cart'), self._cell) r = self.get_positions('direct') n = r.shape[0] dr = r-r0 c = np.abs(np.array((dr-1, dr, dr+1))) diff = np.array([[np.argmin(c[:,i,j]) for j in range(3)] for i in range(n)]) - 1 # (-1,0,1) dr += diff if not silent and np.max(dr) > 0.1: print u"Warning: largest displacement of %.1f (direct units) is rather large..." % (np.max(dr)) self.set_positions(r0+dr, 'direct')