Integrated Computational Materials Engineering (ICME)

Preprocessing and Postprocessing Codes - csg.py

It is a python based code to generate the basic crystal structures

#!/usr/bin/python
import math
import os
import sys

a = float(sys.argv[1])

dataout = file('bcc.POSCAR', 'w')
b = a
c = a
dataout.write("Position data for a BCC system\n")
dataout.write("1\n")
S="  %12f  0.00   0.00\n" % (2*a); dataout.write(S)
S="  0.00  %12f   0.00\n" % (2*b); dataout.write(S)
S="  0.00  0.00   %12f\n" % (2*c); dataout.write(S)
dataout.write("16\n") # 2X2X2 X2(basis atoms) = 16 atoms
dataout.write("Cartesian\n")

count = 1
for i in range(2):
  for j in range(2):
    for k in range(2):
      S = "%i  1 %12f %12f %12f\n" % (count, i*a, j*b, k*c);   dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+a/2,j*b+b/2,k*c+c/2);dataout.write(S); count=count+1
dataout.close()


dataout = file('fcc.POSCAR', 'w')
b = a
c = a
dataout.write("Position data for a BCC system\n")
dataout.write("1\n")
S="  %12f  0.00   0.00\n" % (2*a); dataout.write(S)
S="  0.00  %12f   0.00\n" % (2*b); dataout.write(S)
S="  0.00  0.00   %12f\n" % (2*c); dataout.write(S)
dataout.write("32\n") # 2X2X2 X4(basis atoms) = 32 atoms
dataout.write("Cartesian\n")

count = 1
for i in range(2):
  for j in range(2):
    for k in range(2):
      S = "%i  1 %12f %12f %12f\n" % (count, i*a, j*b, k*c); dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+a/2,j*b+b/2,k*c);dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+a/2,j*b,k*c+c/2);dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a,j*b+b/2,k*c+c/2);dataout.write(S); count=count+1
dataout.close()


dataout = file('hcp.POSCAR', 'w')
b = a*math.sqrt(3)
c = 1.6329*a
dataout.write("Position data for a BCC system\n")
dataout.write("1\n")
S="  %12f  0.00   0.00\n" % (2*a); dataout.write(S)
S="  0.00  %12f   0.00\n" % (2*b); dataout.write(S)
S="  0.00  0.00   %12f\n" % (2*c); dataout.write(S)
dataout.write("32\n") # 2X2X2 X4(basis atoms) = 32 atoms
dataout.write("Cartesian\n")

count = 1
for i in range(2):
  for j in range(2):
    for k in range(2):
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+a/4, j*b+b/3, k*c+c/4); dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+3*a/4,j*b+5*b/6,k*c+c/4);dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+a/4,j*b,k*c+3*c/4);dataout.write(S); count=count+1
      S = "%i  1 %12f %12f %12f\n" % (count, i*a+3*a/4,j*b+b/2,k*c+3*c/4);dataout.write(S); count=count+1
dataout.close()