Skip to content

Commit

Permalink
auto
Browse files Browse the repository at this point in the history
  • Loading branch information
dimonaks committed Dec 6, 2016
1 parent 78dcbc1 commit d846a9e
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 70 deletions.
28 changes: 20 additions & 8 deletions calc_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@ def add_loop(it, setlist, verlist, calc = None, conv = None, varset = None,
if it_folder == None:
print_and_log('Error! Please provide local folder for new ', it, 'structure using *it_folder* argument! ', imp = 'Y')

mat_proj_st_id, input_geo_file = get_structure_from_matproj(struct_des, it, it_folder, verlist[0], mat_proj_cell, mat_proj_id)
st = get_structure_from_matproj(it, it_folder, verlist[0], mat_proj_cell, mat_proj_id)
mat_proj_st_id = st.mat_proj_st_id
input_geo_file = st.input_geo_file
input_geo_format = 'vasp'

elif input_geo_format == 'cee_database':
Expand Down Expand Up @@ -3107,7 +3109,7 @@ def get_structure_from_cee_database(it, it_folder, ver, cee_struct_type = 'exp',



def get_structure_from_matproj(struct_des, it, it_folder, ver, mat_proj_cell = None, mat_proj_id = None):
def get_structure_from_matproj(it = None, it_folder = None, ver = None, mat_proj_cell = '', mat_proj_id = None):
"""
Take structures from Mat. projects
Expand Down Expand Up @@ -3166,14 +3168,24 @@ def get_structure_from_matproj(struct_des, it, it_folder, ver, mat_proj_cell = N
# print(st_pmg.lattice)
# sys.exit()

if it:
add_des(header.struct_des, it, it_folder, des = 'taken automatically from materialsproject.org: '+groundstate_st_id,)
path2poscar = it_folder+'/'+it+'/'+groundstate_st_id+".POSCAR-"+str(ver)
makedir(path2poscar)
else:
path2poscar = groundstate_st_id+".POSCAR"

add_des(struct_des, it, it_folder, des = 'taken automatically from materialsproject.org: '+groundstate_st_id,)
path2poscar = it_folder+'/'+it+'/'+groundstate_st_id+".POSCAR-"+str(ver)
makedir(path2poscar)
Poscar(st_pmg).write_file(path2poscar, direct=True, vasp4_compatible=True, )
print_and_log("File "+path2poscar+" was written\n")

return groundstate_st_id, path2poscar
Poscar(st_pmg).write_file(path2poscar, direct=True, vasp4_compatible=True, )
print_and_log('Structure', groundstate_st_id, 'downloaded from materialsproject.org\n',
'File '+path2poscar+" was written", imp = 'y')

st = smart_structure_read(input_geo_file = path2poscar)
st.groundstate_st_id = groundstate_st_id
st.input_geo_file = path2poscar


return st

#pymatgen drafts, can be useful

Expand Down
6 changes: 4 additions & 2 deletions classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from small_functions import cat_files, grep_file
from functions import (read_vectors, read_list, words, local_surrounding,
xred2xcart, xcart2xred, element_name_inv, calculate_voronoi,
get_from_server, push_to_server, run_on_server, list2string, makedir, write_xyz)
get_from_server, push_to_server, run_on_server, list2string, makedir, write_xyz, write_lammps)



Expand Down Expand Up @@ -336,8 +336,10 @@ def write_cif(self, filename):

def write_xyz(self, *args, **kwargs):
#see description for write_xyz()
return write_xyz(*args, **kwargs)
return write_xyz(self, *args, **kwargs)

def write_lammps(self, *args, **kwargs):
return write_lammps(self, *args, **kwargs)



Expand Down
129 changes: 74 additions & 55 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ def makedir(path):
*path* - path to some file
Make dirname(path) directory if it does not exist
"""
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
print_and_log("Directory "+os.path.dirname(path)+" was created\n")
dirname = os.path.dirname(path)

if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
print_and_log("Directory", dirname, " was created", imp = 'y')
return


Expand Down Expand Up @@ -931,13 +933,12 @@ def update_var():
return


def write_lammps(cl, state, filepath = ''):
"""Writes structure in lammps format """
if state == 'end':
st = cl.end
elif state == 'init':
st = cl.init

def write_lammps(st, filename = '', charges = None):
"""Writes structure in lammps format
charges (list of float) - list of charges for each atom type
"""

rprimd = st.rprimd
xcart = st.xcart
xred = st.xred
Expand All @@ -948,76 +949,94 @@ def write_lammps(cl, state, filepath = ''):
natom = st.natom

if natom != len(xred) != len(xcart) != len(typat) or len(znucl) != max(typat):
print_and_log( "Error! write_xyz: check your arrays.\n\n" )
print_and_log( "Error! write_xyz: check your structure" )

if name == '': name = 'noname'
if name == '':
name = 'noname'
if xcart == [] or len(xcart) != len(xred):
print_and_log( "Warining! write_xyz: len(xcart) != len(xred) making xcart from xred.\n", imp = 'y')
xcart = xred2xcart(xred, rprimd)
#print xcart[1]

if not filepath:
filepath = 'lammps/'+name+".lammps"
if not os.path.exists(os.path.dirname(filepath)):
os.makedirs(os.path.dirname(filepath))
if not filename:
filename = 'lammps/'+name

filename+='.inp'

makedir(filename)



"""Write lammps structure file; """
if 0:
if 1:
""" My version; valid only for octahedral cells"""
with open(filepath+'','w') as f:
printlog( "Warining! write_lammps(): this func supports only orthogonal cells", imp = 'Y')

with open(filename+'','w') as f:
f.write("Lammps format "+name+'\n')
f.write(str(natom)+" atoms\n")
f.write(str(ntypat)+" atom types\n")
f.write("0 "+str(rprimd[0][0])+" xlo xhi\n")
f.write("0 "+str(rprimd[1][1])+" ylo yhi\n")
f.write("0 "+str(rprimd[2][2])+" zlo zhi\n")
f.write("0.000000 0.000000 0.000000 xy xz yz\n")
f.write("{:10.8f} {:10.8f} xlo xhi\n".format(0, rprimd[0][0]))
f.write("{:10.8f} {:10.8f} ylo yhi\n".format(0, rprimd[1][1]))
f.write("{:10.8f} {:10.8f} zlo zhi\n".format(0, rprimd[2][2]))
f.write("0.00000000 0.00000000 0.00000000 xy xz yz\n")
f.write("\nAtoms\n\n")

for i, x in enumerate(xcart):
f.write("{0:d} {1:d} {2:f} {3:f} {4:f}\n".format(i+1, typat[i], x[0], x[1], x[2] ))
f.write("{0:8d} {1:2d}".format(i+1, typat[i]))
if charges:
f.write(" {:6.3f}".format(charges[typat[i]-1] ) )
f.write(" {:12.6f} {:12.6f} {:12.6f}\n".format(x[0], x[1], x[2] ))



f.write("\n")

printlog('File', filename, 'was written', imp = 'y')



else:
"""Write poscar and convert from poscar to lammps using external script; Valid for arbitary cells"""
cl.write_structure('POSCAR', 'dir', path = 'voronoi_analysis/', state = state)
runBash("voronoi_analysis/VASP-poscar2lammps.awk voronoi_analysis/POSCAR > "+filepath)




"""Write lammps.in file """
with open('voronoi_analysis/voronoi.in','w') as f:
f.write("""units metal
atom_style atomic
boundary p p p\n""")
f.write("read_data /home/aksenov/programs/Simulation_wrapper/siman1/voronoi_analysis/structure.lammps\n")
# f.write('lattice custom 1 ')
# for i, a in enumerate(rprimd):
# f.write(' a'+str(i+1))
# for x in a:
# f.write(' '+str(x))

# f.write(' &\n')
# for x in xred:
# f.write(' basis {0:f} {1:f} {2:f}&\n '.format(x[0], x[1], x[2]) )
# f.write("""\n
# region 1 prism 0 1 0 1 0 1 1 0 0
# create_box 1 prism
# create_atoms 1 prism""")

for i in range(ntypat):
f.write('\nmass '+str(i+1)+' '+str(int(znucl[i]))+'\n')

f.write('pair_style lj/cut 2.0\n')
for i in range(ntypat):
for j in range(i, ntypat):
f.write('pair_coeff '+str(i+1)+' '+str(j+1)+' 0.0 1.0\n')
if 0:
"""Write lammps.in file """
with open('voronoi_analysis/voronoi.in','w') as f:
f.write("""units metal
atom_style atomic
boundary p p p\n""")
f.write("read_data /home/aksenov/programs/Simulation_wrapper/siman1/voronoi_analysis/structure.lammps\n")
# f.write('lattice custom 1 ')
# for i, a in enumerate(rprimd):
# f.write(' a'+str(i+1))
# for x in a:
# f.write(' '+str(x))
# f.write(' &\n')
# for x in xred:
# f.write(' basis {0:f} {1:f} {2:f}&\n '.format(x[0], x[1], x[2]) )
# f.write("""\n
# region 1 prism 0 1 0 1 0 1 1 0 0
# create_box 1 prism
# create_atoms 1 prism""")

for i in range(ntypat):
f.write('\nmass '+str(i+1)+' '+str(int(znucl[i]))+'\n')
f.write('pair_style lj/cut 2.0\n')
for i in range(ntypat):
for j in range(i, ntypat):
f.write('pair_coeff '+str(i+1)+' '+str(j+1)+' 0.0 1.0\n')


f.write("""compute v1 all voronoi/atom
dump d1 all custom 1 /home/aksenov/programs/Simulation_wrapper/siman1/voronoi_analysis/dump.voro id type x y z c_v1[1] c_v1[2]
run 0
uncompute v1\n""")
f.write("""compute v1 all voronoi/atom
dump d1 all custom 1 /home/aksenov/programs/Simulation_wrapper/siman1/voronoi_analysis/dump.voro id type x y z c_v1[1] c_v1[2]
run 0
uncompute v1\n""")

return

Expand Down
2 changes: 2 additions & 0 deletions geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,6 @@ def determine_symmetry_positions(st, element):
if el in element:
positions[pos].append(i)


printlog('I found ', len(positions), 'non-eqiu')
print(positions)
16 changes: 16 additions & 0 deletions tutorials/mp-7000.POSCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Si3 O6
1.0
5.021502 0.000000 0.000000
-2.510751 4.348749 0.000000
0.000000 0.000000 5.510570
6 3
direct
0.256094 0.414854 0.794543 O
0.585146 0.841240 0.127877 O
0.158760 0.743906 0.461210 O
0.414854 0.256094 0.205457 O
0.743906 0.158760 0.538790 O
0.841240 0.585146 0.872123 O
0.523695 0.523695 0.000000 Si
0.000000 0.476305 0.666667 Si
0.476305 0.000000 0.333333 Si

0 comments on commit d846a9e

Please sign in to comment.