本文整理汇总了Python中atom.Atom.set_pos方法的典型用法代码示例。如果您正苦于以下问题:Python Atom.set_pos方法的具体用法?Python Atom.set_pos怎么用?Python Atom.set_pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atom.Atom
的用法示例。
在下文中一共展示了Atom.set_pos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: structure2aSys
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
示例2: repeat
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def repeat(self,n1,n2,n3):
#...unit vectors to be repeated
self.a1= self.a1*n1
self.a2= self.a2*n2
self.a3= self.a3*n3
n123= n1*n2*n3
nsid= 0
for ai in self.atoms:
nsid= max(nsid,ai.sid)
natm0= self.num_atoms()
atoms0= copy.copy(self.atoms)
self.atoms= []
aid= 0
for i1 in range(n1):
for i2 in range(n2):
for i3 in range(n3):
for ai0 in atoms0:
aid += 1
ai= Atom()
ai.sid= ai0.sid
ai.symbol= ai0.symbol
ai.ifmv= ai0.ifmv
x= ai0.pos[0]/n1 +1.0/n1*i1
y= ai0.pos[1]/n2 +1.0/n2*i2
z= ai0.pos[2]/n3 +1.0/n3*i3
ai.set_pos(x,y,z)
ai.set_vel(ai0.vel[0],ai0.vel[1],ai0.vel[2])
ai.set_id(aid)
self.atoms.append(ai)
示例3: from_ase_atoms
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def from_ase_atoms(self,atoms):
"""
Convert ASE Atoms object to NAPSystem object.
"""
self.a1 = np.array(atoms.cell[0])
self.a2 = np.array(atoms.cell[1])
self.a3 = np.array(atoms.cell[2])
spos = atoms.get_scaled_positions()
symbols = atoms.get_chemical_symbols()
#...initialize and remake self.specorder
self.specorder = []
for s in symbols:
if s not in self.specorder:
self.specorder.append(s)
#...first, initialize atoms array
self.atoms = []
#...append each atom from ASE-Atoms
for ia,spi in enumerate(spos):
si = symbols[ia]
ai = Atom()
sid = self.specorder.index(si)+1
ai.set_id(ia+1)
ai.set_sid(sid)
ai.set_symbol(si)
ai.set_pos(spi[0],spi[1],spi[2])
ai.set_vel(0.,0.,0.)
self.atoms.append(ai)
return
示例4: read_akr
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def read_akr(self,fname='akr0000'):
f=open(fname,'r')
# 1st: lattice constant
self.alc= float(f.readline().split()[0])
# 2nd-4th: cell vectors
for i in range(3):
data= f.readline().split()
self.a1[i]= float(data[0])
self.a2[i]= float(data[1])
self.a3[i]= float(data[2])
# 5th: num of atoms
natm= int(f.readline().split()[0])
# 9th-: atom positions
self.atoms= []
symbol = None
for i in range(natm):
data= [float(x) for x in f.readline().split()]
ai= Atom()
ai.set_sid(data[0])
ai.set_pos(data[1],data[2],data[3])
ai.set_vel(data[4],data[5],data[6])
if self.specorder:
symbol = self.specorder[ai.sid-1]
if symbol and ai.symbol != symbol:
ai.set_symbol(symbol)
self.atoms.append(ai)
f.close()
示例5: read_POSCAR
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def read_POSCAR(self,fname='POSCAR'):
with open(fname,'r') as f:
# 1st line: comment
f.readline()
# 2nd: lattice constant
self.alc= float(f.readline().split()[0])
# 3rd-5th: cell vectors
self.a1= np.array([float(x) for x in f.readline().split()])
self.a2= np.array([float(x) for x in f.readline().split()])
self.a3= np.array([float(x) for x in f.readline().split()])
# 6th: species names or number of each species
buff= f.readline().split()
if not buff[0].isdigit():
spcs = copy.deepcopy(buff)
buff= f.readline().split()
if not self.specorder:
self.specorder = spcs
num_species= np.array([ int(n) for n in buff])
natm= 0
for n in num_species:
natm += n
#print("Number of atoms = {0:5d}".format(natm))
# 7th or 8th line: comment
c7= f.readline()
if c7[0] in ('s','S'):
c8= f.readline()
# Atom positions hereafter
self.atoms= []
for i in range(natm):
buff= f.readline().split()
ai= Atom()
sid= 1
m= 0
sindex=0
symbol = None
for n in num_species:
m += n
if i < m:
if spcs and self.specorder:
sid = self.specorder.index(spcs[sindex]) + 1
symbol = spcs[sindex]
break
sid += 1
sindex += 1
ai.set_id(i+1)
ai.set_sid(sid)
if symbol:
ai.symbol = symbol
ai.set_pos(float(buff[0]),float(buff[1]),float(buff[2]))
ai.set_vel(0.0,0.0,0.0)
self.atoms.append(ai)
示例6: make_sc
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
示例7: make_bcc
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
示例8: doc_to_pos
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
示例9: read_pmd
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def read_pmd(self,fname='pmd0000'):
f=open(fname,'r')
# 1st: lattice constant
self.alc= float(f.readline().split()[0])
# 2nd-4th: cell vectors
# for i in range(3):
# data= f.readline().split()
# self.a1[i]= float(data[0])
# self.a2[i]= float(data[1])
# self.a3[i]= float(data[2])
self.a1= np.array([float(x) for x in f.readline().split()])
self.a2= np.array([float(x) for x in f.readline().split()])
self.a3= np.array([float(x) for x in f.readline().split()])
# 5th-7th: velocity of cell vectors
tmp= f.readline().split()
tmp= f.readline().split()
tmp= f.readline().split()
# 8st: num of atoms
natm= int(f.readline().split()[0])
# 9th-: atom positions
self.atoms= []
symbol = None
for i in range(natm):
data= [float(x) for x in f.readline().split()]
ai= Atom()
ai.decode_tag(data[0])
if self.specorder:
symbol = self.specorder[ai.sid-1]
if symbol and ai.symbol != symbol:
ai.set_symbol(symbol)
ai.set_pos(data[1],data[2],data[3]) # position
ai.set_vel(data[4],data[5],data[6]) # velocity
ai.set_ekin(data[7])
ai.set_epot(data[8])
ai.set_strs(data[9],data[10],data[11],
data[12],data[13],data[14])
self.atoms.append(ai)
f.close()
示例10: print
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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)
asys.add_atom(atom3)
da = (amax-amin)/nsmpl
示例11: print
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
os.system('cp pmdini pmdorig')
fout= open('out.2body','w')
for ip in range(nsmpl+1):
示例12: range
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
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
p3= (ai0.pos[2]+i3)/r3
ai.set_pos(p1,p2,p3)
sysext.add_atom(ai)
sysext.reset_ids()
natme= sysext.num_atoms()
print ' sysext.num_atoms()=',natme
# for ai in sysext.atoms:
# print ai.pos
os.system('cp pmd0000 pmd0000.orig')
#...loop for all atoms in the extended system
fcmat= np.zeros((natme,natme,3,3))
for ia in range(natme):
print '.',
sys.stdout.flush()
示例13: make_polycrystal
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def make_polycrystal(grns, uc, n1, n2, n3):
u"""
This routine is not that universal.
Each grain has to have neighboring grains within a supercell,
otherwise there will be some unexpecting grain boundries.
In order to do so, the system should be large enough and
the number of grains should be large enough.
"""
sv = shift_vector()
system = AtomSystem()
system.set_lattice(uc.alc, uc.a1 * n1, uc.a2 * n2, uc.a3 * n3)
hmat = np.zeros((3, 3))
hmat[0] = system.a1 * system.alc
hmat[1] = system.a2 * system.alc
hmat[2] = system.a3 * system.alc
hmati = np.linalg.inv(hmat)
for ig in range(len(grns)):
grain = grns[ig]
rmat = grain.rmat
pi = grain.point
api = np.dot(hmat, pi)
for ix in range(-n1 / 2 - 1, n1 / 2 + 2):
print "ix=", ix
for iy in range(-n2 / 2 - 1, n2 / 2 + 2):
for iz in range(-n3 / 2 - 1, n3 / 2 + 2):
for m in range(len(uc.atoms)):
rt = np.zeros((3,))
rt[0] = (uc.atoms[m].pos[0] + ix) / n1
rt[1] = (uc.atoms[m].pos[1] + iy) / n2
rt[2] = (uc.atoms[m].pos[2] + iz) / n3
# ...rt to absolute position
art = np.dot(hmat, rt)
# ...rotate
ari = np.dot(rmat, art)
ari[0] = ari[0] + api[0]
ari[1] = ari[1] + api[1]
ari[2] = ari[2] + api[2]
# #...reduce into the supercell
# ri= np.dot(hmati,ari)
# ri[0]= pbc(ri[0])
# ri[1]= pbc(ri[1])
# ri[2]= pbc(ri[2])
# ari= np.dot(hmat,ri)
# ...check distance from all the grain points
di = distance(ari, api)
isOutside = False
for jg in range(len(grns)):
gj = grns[jg]
for isv in range(27):
pj = gj.point
if jg == ig and isv == 13:
continue
svi = sv[isv]
pj = pj + svi
apj = np.dot(hmat, pj)
dj = distance(ari, apj)
if dj < di:
isOutside = True
break
if isOutside:
break
if isOutside:
break
# ...here ri is inside this grain, register it
atom = Atom()
ri = np.dot(hmati, ari)
ri[0] = pbc(ri[0])
ri[1] = pbc(ri[1])
ri[2] = pbc(ri[2])
atom.set_pos(ri[0], ri[1], ri[2])
atom.set_sid(uc.atoms[m].sid)
system.add_atom(atom)
# ...remove too-close atoms at the grain boundaries
system.make_pair_list(rcut)
ls_remove = []
dmin2 = dmin ** 2
xij = np.zeros((3,))
for ia in range(system.num_atoms()):
ai = system.atoms[ia]
pi = ai.pos
nlst = system.nlspr[ia]
lst = system.lspr[ia]
for j in range(nlst):
ja = lst[j]
aj = system.atoms[ja]
pj = aj.pos
xij[0] = pj[0] - pi[0] - anint(pj[0] - pi[0])
xij[1] = pj[1] - pi[1] - anint(pj[1] - pi[1])
xij[2] = pj[2] - pi[2] - anint(pj[2] - pi[2])
xij = np.dot(hmat, xij)
d2 = xij[0] ** 2 + xij[1] ** 2 + xij[2] ** 2
if d2 < dmin2:
ls_remove.append(ia)
ls_remove.append(ja)
# ...one of two will survive
# print ls_remove
count = [ls_remove.count(ls_remove[i]) for i in range(len(ls_remove))]
# print count
for i in range(0, len(ls_remove), 2):
if count[i] > count[i + 1]:
#.........这里部分代码省略.........
示例14: enumerate
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
hmat= psnew.get_hmat()
hi = np.linalg.inv(hmat)
for ia,posi in enumerate(expos):
sposi = np.dot(hi,posi)
if 0.0 <= sposi[0] < 1.0 and \
0.0 <= sposi[1] < 1.0 and \
0.0 <= sposi[2] < 1.0:
atom = Atom()
symbol = exsymbols[ia]
print('{0:5d} {1:s}'.format(ia,symbol)
+' {0:12.5f} {1:12.5f} {2:12.5f}'.format(sposi[0],
sposi[1],
sposi[2]))
atom.set_symbol(symbol)
atom.set_pos(sposi[0],sposi[1],sposi[2])
psnew.add_atom(atom)
tmp = None
#tmp = raw_input('Input periodic shift vector if you want: ')
tmp = ' 0.5, 0.0, 0.5'
if tmp:
shift = [ float(x) for x in tmp.split(',')]
for a in psnew.atoms:
a.pos[0] += shift[0]
a.pos[1] += shift[1]
a.pos[2] += shift[2]
psnew.assign_pbc()
psnew.write_POSCAR(infile+'.new')
print('Check '+infile+'.new')
示例15: read_xsf
# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import set_pos [as 别名]
def read_xsf(self,fname="xsf"):
f=open(fname,'r')
mode= 'None'
ixyz= 0
iatm= 0
self.atoms= []
natm= 0
for line in f.readlines():
if 'CRYSTAL' in line:
mode= 'CRYSTAL'
continue
elif 'PRIMVEC' in line:
mode= 'PRIMVEC'
continue
elif 'PRIMCOORD' in line:
mode= 'PRIMCOORD'
# Before going further, create inversed h-matrix
hi = unitvec_to_hi(self.a1,self.a2,self.a3)
# print 'Inversed h-matrix:'
# print hi
continue
if mode == 'CRYSTAL':
pass
elif mode == 'PRIMVEC':
if ixyz == 0:
arr = [ float(x) for x in line.split() ]
self.a1[0] = arr[0]
self.a1[1] = arr[1]
self.a1[2] = arr[2]
elif ixyz == 1:
arr = [ float(x) for x in line.split() ]
self.a2[0] = arr[0]
self.a2[1] = arr[1]
self.a2[2] = arr[2]
elif ixyz == 2:
arr = [ float(x) for x in line.split() ]
self.a3[0] = arr[0]
self.a3[1] = arr[1]
self.a3[2] = arr[2]
ixyz += 1
elif mode == 'PRIMCOORD':
data = line.split()
if len(data) == 1:
natm= int(data[0])
continue
elif len(data) == 2:
natm= int(data[0])
nspcs= int(data[1])
continue
elif len(data) == 4 or len(data) == 7:
if iatm >= natm:
continue
symbol = get_symbol_from_number(int(data[0]))
if symbol not in self.specorder:
self.specorder.append(symbol)
sid = self.specorder.index(symbol) +1
ai= Atom()
ai.symbol = symbol
ai.set_sid(sid)
xc= float(data[1])
yc= float(data[2])
zc= float(data[3])
xi,yi,zi = cartessian_to_scaled(hi,xc,yc,zc)
ai.set_pos(xi,yi,zi)
ai.set_vel(0.0,0.0,0.0)
self.atoms.append(ai)
# print 'iatm,symbol,sid,xc,yc,zc = ',iatm,symbol,sid,xc,yc,zc
else:
continue
iatm += 1
self.alc= 1.0
# print self.alc
# print self.a1[:]
# print self.a2[:]
# print self.a3[:]
f.close()