def structure2aSys(structure,idoffset=1): """ Converts Structure object of pymatgen to NAPSystem object in nap. Args: structure (Structure): pymatgen Structure object to be converted to NAPSystem object.. Returns: aSys (NAPSystem): """ lattice= structure.lattice alc= 1.0 a1= np.array(lattice.matrix[0]) a2= np.array(lattice.matrix[1]) a3= np.array(lattice.matrix[2]) #... rescale a? vectors a1= a1/alc a2= a2/alc a3= a3/alc aSys= NAPSystem() aSys.set_lattice(alc,a1,a2,a3) for ia in range(structure.num_sites): ai= Atom() si= structure[ia] crd= si.frac_coords ai.set_pos(crd[0],crd[1],crd[2]) sid= structure.symbol_set.index(si.species_string)+idoffset ai.set_sid(sid) ai.set_id(ia+1) aSys.add_atom(ai) return aSys
def structure2aSys(structure, idoffset=1): """ Converts Structure object of pymatgen to NAPSystem object in nap. Args: structure (Structure): pymatgen Structure object to be converted to NAPSystem object.. Returns: aSys (NAPSystem): """ lattice = structure.lattice alc = 1.0 a1 = np.array(lattice.matrix[0]) a2 = np.array(lattice.matrix[1]) a3 = np.array(lattice.matrix[2]) #... rescale a? vectors a1 = a1 / alc a2 = a2 / alc a3 = a3 / alc aSys = NAPSystem() aSys.set_lattice(alc, a1, a2, a3) for ia in range(structure.num_sites): ai = Atom() si = structure[ia] crd = si.frac_coords ai.set_pos(crd[0], crd[1], crd[2]) sid = structure.symbol_set.index(si.species_string) + idoffset ai.set_sid(sid) ai.set_id(ia + 1) aSys.add_atom(ai) return aSys
def make_sc(latconst=1.0): """ Make a cell of simple cubic structure. """ s= NAPSystem(specorder=_default_specorder) #...lattice a1= np.array([ 1.0, 0.0, 0.0 ]) a2= np.array([ 0.0, 1.0, 0.0 ]) a3= np.array([ 0.0, 0.0, 1.0 ]) s.set_lattice(latconst,a1,a2,a3) p=[0.00, 0.00, 0.00] atom= Atom() atom.set_pos(p[0],p[1],p[2]) atom.set_symbol(_default_specorder[0]) s.add_atom(atom) return s
def make_bcc(latconst=1.0): """ Make a cell of bcc structure. """ s= NAPSystem(specorder=_default_specorder) #...lattice a1= np.array([ 1.0, 0.0, 0.0 ]) a2= np.array([ 0.0, 1.0, 0.0 ]) a3= np.array([ 0.0, 0.0, 1.0 ]) s.set_lattice(latconst,a1,a2,a3) positions=[(0.00, 0.00, 0.00), (0.50, 0.50, 0.50)] for p in positions: atom= Atom() atom.set_pos(p[0],p[1],p[2]) atom.set_symbol(_default_specorder[0]) s.add_atom(atom) return s
def doc_to_pos(doc,conf): """ Make a pos file, which has pmd format, from a document in MongoDB. """ psys= NAPSystem() matrix=doc['calculations'][-1]['output']['crystal']['lattice']['matrix'] a1= matrix[0] a2= matrix[1] a3= matrix[2] psys.set_lattice(1.0,a1,a2,a3) species_ids=conf['species_ids'] sites= doc['calculations'][-1]['output']['crystal']['sites'] for site in sites: ra= site['abc'] ai= Atom() ai.set_pos(ra[0],ra[1],ra[2]) ai.set_sid(species_ids[site['species'][0]['element']]) psys.add_atom(ai) return psys
def doc_to_pos(doc, conf): """ Make a pos file, which has pmd format, from a document in MongoDB. """ psys = NAPSystem() matrix = doc['calculations'][-1]['output']['crystal']['lattice']['matrix'] a1 = matrix[0] a2 = matrix[1] a3 = matrix[2] psys.set_lattice(1.0, a1, a2, a3) species_ids = conf['species_ids'] sites = doc['calculations'][-1]['output']['crystal']['sites'] for site in sites: ra = site['abc'] ai = Atom() ai.set_pos(ra[0], ra[1], ra[2]) ai.set_sid(species_ids[site['species'][0]['element']]) psys.add_atom(ai) return psys
print ' rcut = ', rcut, ' Ang.' rmin = options.rmin print ' rmin = ', rmin, ' Ang.' sid1 = options.sid1 print ' sid1 = ', sid1 sid2 = options.sid2 print ' sid2 = ', sid2 pmdexec = options.pmdexec asys = NAPSystem() # system size is bigger than 2*rcut a1 = np.array([2.0, 0.0, 0.0]) a2 = np.array([0.0, 1.0, 0.0]) a3 = np.array([0.0, 0.0, 1.0]) alc = rcut asys.set_lattice(alc, a1, a2, a3) atom1 = Atom() atom2 = Atom() atom1.set_pos(0.0, 0.0, 0.0) atom1.set_id(1) atom1.set_sid(sid1) asys.add_atom(atom1) atom2.set_pos(0.5, 0.0, 0.0) atom2.set_id(2) atom2.set_sid(sid2) asys.add_atom(atom2) hmin = rmin / (2 * rcut) hd = (0.5 - hmin) / nsmpl
natm0 = sys0.num_atoms() h0 = np.zeros((3, 3)) h0[0] = sys0.a1 * sys0.alc h0[1] = sys0.a2 * sys0.alc h0[2] = sys0.a3 * sys0.alc n1, n2, n3 = calc_extention_ratio(h0, rcut) r1 = 2 * n1 + 1 r2 = 2 * n2 + 1 r3 = 2 * n3 + 1 print ' num of cells in each axis=', r1, r2, r3 print ' num of atoms in extended system=', natm0 * r1 * r2 * r3 sysext = NAPSystem() sysext.set_lattice(sys0.alc, np.multiply(sys0.a1, r1), np.multiply(sys0.a2, r2), np.multiply(sys0.a3, r3)) hext = np.zeros((3, 3)) hext[0] = sysext.a1 * sysext.alc hext[1] = sysext.a2 * sysext.alc hext[2] = sysext.a3 * sysext.alc #...make extended system corresponding to the phonopy definition for ia in range(natm0): ai0 = sys0.atoms[ia] for i3 in range(r3): for i2 in range(r2): for i1 in range(r1): ai = Atom() ai.set_sid(ai0.sid) p1 = (ai0.pos[0] + i1) / r1 p2 = (ai0.pos[1] + i2) / r2
rcut= options.rcut print(' rcut = ',rcut,' Ang.') amin= options.amin print(' amin = ',amin) amax= options.amax print(' amax = ',amax) distance= options.distance print(' distance = ',distance,' Ang.') pmdexec= options.pmdexec asys= NAPSystem() a1= np.array([2.0, 0.0, 0.0]) a2= np.array([0.0, 2.0, 0.0]) a3= np.array([0.0, 0.0, 1.0]) alc= rcut asys.set_lattice(alc,a1,a2,a3) atom1= Atom() atom1.set_pos(0.0,0.0,0.0) atom1.set_id(1) asys.add_atom(atom1) hd= distance/(alc*2) atom2= Atom() atom2.set_pos(hd,0.0,0.0) atom2.set_id(2) asys.add_atom(atom2) atom3= Atom() atom3.set_pos(0.0,0.0,0.0) atom3.set_id(3)
h0=np.zeros((3,3)) h0[0]= sys0.a1 *sys0.alc h0[1]= sys0.a2 *sys0.alc h0[2]= sys0.a3 *sys0.alc n1,n2,n3= calc_extention_ratio(h0,rcut) r1= 2*n1+1 r2= 2*n2+1 r3= 2*n3+1 print ' num of cells in each axis=',r1,r2,r3 print ' num of atoms in extended system=',natm0*r1*r2*r3 sysext= NAPSystem() sysext.set_lattice( sys0.alc ,np.multiply(sys0.a1,r1) ,np.multiply(sys0.a2,r2) ,np.multiply(sys0.a3,r3)) hext=np.zeros((3,3)) hext[0]= sysext.a1 *sysext.alc hext[1]= sysext.a2 *sysext.alc hext[2]= sysext.a3 *sysext.alc #...make extended system corresponding to the phonopy definition for ia in range(natm0): ai0= sys0.atoms[ia] for i3 in range(r3): for i2 in range(r2): for i1 in range(r1): ai= Atom() ai.set_sid(ai0.sid) p1= (ai0.pos[0]+i1)/r1
sa2new[:] = [ 0.0, 1.0, 0.0 ] #tmp = raw_input('Input new a3 vector: ') #a3new[:] = [ float(x) for x in tmp.split(',') ] sa3new[:] = [ 0.5, 0.5, 1.0 ] hmat = psys.get_hmat() a1new = np.dot(hmat,sa1new) a2new = np.dot(hmat,sa2new) a3new = np.dot(hmat,sa3new) print('new a1 in hmat_orig =',sa1new) print('new a2 in hmat_orig =',sa2new) print('new a3 in hmat_orig =',sa3new) print('new a1 =',a1new) print('new a2 =',a2new) print('new a3 =',a3new) psnew = NAPSystem(specorder=specorder) psnew.set_lattice(psys.alc,a1new,a2new,a3new) # Expand the original system for the search of atoms to be included # in the new system. # First, compute how much we have to expand the original system hi = np.linalg.inv(hmat) icsa1new = [0,0,0] icsa2new = [0,0,0] icsa3new = [0,0,0] for i in range(3): if sa1new[i] < 0.0: icsa1new[i] = int(sa1new[i]-1.0) else: icsa1new[i] = int(sa1new[i]+1.0) if sa2new[i] < 0.0: icsa2new[i] = int(sa2new[i]-1.0)