Commit 7ec3da86 authored by Sherri Hadian's avatar Sherri Hadian
Browse files

committing the merged changes

parents 8aad3ddc 9ad7fef2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,5 +8,5 @@ log.file
io_file
Readme
.ipynb_checkpoints

POS*
+1434 −14

File changed.

Preview size limit exceeded, changes collapsed.

+48 −12
Original line number Diff line number Diff line
@@ -5,13 +5,21 @@ This module is a collection of functions that produce CSL properties.
When run from the terminal, the code runs in two modes.

 First mode:
<<<<<<< HEAD
  'python CSLgenerator.py axis(u v w) [limit]' ----->  Where the u v w are the
=======
  'python CSLgenerator.py u v w [limit]' ----->  Where the u v w are the
>>>>>>> development
  indices of the rotation axis such as 1 0 0, 1 1 1, 1 1 0 and so on. The limit
  is the maximum Sigma of interest.
  (the limit by default: 100)

 Second mode:
<<<<<<< HEAD
 'python CSLgenerator.py axis(u v w) basis sigma [limit]' -----> Where basis is
=======
 'python CSLgenerator.py u v w basis sigma [limit]' -----> Where basis is
>>>>>>> development
  either fcc, bcc, diamond or sc. You read the sigma of interest from the first
  mode run. The limit here refers to CSL GB inclinations. The bigger the limit,
  the higher the indices of CSL planes.
@@ -126,7 +134,11 @@ def ang(a, b):

def CommonDivisor(a):
    """
<<<<<<< HEAD
    returns the reduced vector and the common factor of vector a.
=======
    returns the common factor of vector a and the reduced vector.
>>>>>>> development
    """
    CommFac = []
    a = np.array(a)
@@ -200,8 +212,13 @@ def Tilt_Twist_comp(v1, uvw, m, n):
        twist = 2 * acos(cos(theta / 2) / cos(radians(tilt / 2)))
        print("Tilt component: {0:<6.2f} Twist component: {1:6.2f}"
                     .format(tilt, twist))
<<<<<<< HEAD


=======


>>>>>>> development
def Create_Possible_GB_Plane_List(uvw, m=5, n=1, lim=5):
    """
    generate GB planes and specifies the character.
@@ -639,28 +656,34 @@ def Write_to_io(axis, m, n, basis):
    """

    my_dict = {'GB_plane': str([axis[0], axis[1], axis[2]]), 'lattice_parameter': '4',
               'overlap_distance': '0.3', 'which_g': 'g1',
               'overlap_distance': '0.0', 'which_g': 'g1',
               'rigid_trans': 'no', 'a': '10', 'b': '5',
               'dimensions': '[1,1,1]'}
               'dimensions': '[1,1,1]',
               'File_type': 'LAMMPS'}

    with open('io_file', 'w') as f:
        f.write('### input parameters for gb_generator.py ### \n')
        f.write('# CSL plane of interest that you read from the output of '
                'csl_generator as GB1 \n \n')
                'csl_generator as GB1 \n')
        f.write(list(my_dict.keys())[0] + ': ' + list(my_dict.values())[0] +
<<<<<<< HEAD
                '\n')
        f.write('# lattice parameter in Angstrom \n \n')
=======
                '\n\n')
        f.write('# lattice parameter in Angstrom \n')
>>>>>>> development
        f.write(list(my_dict.keys())[1] + ': ' + list(my_dict.values())[1] +
                '\n')
                '\n\n')
        f.write('# atoms that are closer than this fraction of the lattice '
                'parameter will be removed \n')
        f.write('# either from grain1 (g1) or from grain2 (g2). If you choose '
                '0 no atoms will be removed \n\n')
                '0 no atoms will be removed \n')
        f.write(list(my_dict.keys())[2] + ': ' + list(my_dict.values())[2] +
                '\n')
        f.write('# decide which grain the atoms should be removed from \n\n')
                '\n\n')
        f.write('# decide which grain the atoms should be removed from \n')
        f.write(list(my_dict.keys())[3]+': ' + str(list(my_dict.values())[3]) +
                '\n')
                '\n\n')
        f.write('# decide whether you want rigid body translations to be done '
                'on the GB_plane or not (yes or no)\n')

@@ -668,7 +691,7 @@ def Write_to_io(axis, m, n, basis):
        '# CSL vectors will be divided by integers a and b to produce a*b initial \n'
        '# configurations. The default values produce 50 initial structures \n'
        '# if you choose no for rigid_trans, you do not need to care about a and b. \n'
        '# twist boundaries are handled internally \n\n')
        '# twist boundaries are handled internally \n')

        f.write(list(my_dict.keys())[4] + ': ' +
                str(list(my_dict.values())[4]) + '\n')
@@ -677,12 +700,15 @@ def Write_to_io(axis, m, n, basis):
                str(list(my_dict.values())[5]) + '\n')

        f.write(list(my_dict.keys())[6] + ': ' +
                str(list(my_dict.values())[6]) + '\n')
                str(list(my_dict.values())[6]) + '\n\n')

        f.write('# dimensions of the supercell in: [l1,l2,l3],  where l1 is'
                'the direction along the GB_plane normal\n')
        f.write('#  and l2 and l3 are inplane dimensions\n\n')
        f.write('#  and l2 and l3 are inplane dimensions \n')
        f.write(list(my_dict.keys())[7] + ': ' + list(my_dict.values())[7] +
                '\n\n')
        f.write('# File type, either VASP or LAMMPS input \n')
        f.write(list(my_dict.keys())[8] + ': ' + list(my_dict.values())[8] +
                '\n\n\n')
        f.write('# The following is your csl_generator output. YOU DO NOT NEED '
                'TO CHANGE THEM! \n\n')
@@ -702,12 +728,15 @@ def main():
        print(__doc__)
    else:
        uvw = np.array([int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])])
        uvw = CommonDivisor(uvw)[0]


    if len(sys.argv) == 4:
        limit = 100
        print("   List of possible CSLs for {} axis sorted by Sigma   "
              .format(str(uvw)))
        print_list(uvw, limit)
        print("\n Choose a basis, pick a sigma and use the second mode!\n")

    if len(sys.argv) == 5:

@@ -716,6 +745,7 @@ def main():
            print("    List of possible CSLs for {} axis sorted by Sigma   "
                  .format(str(uvw)))
            print_list(uvw, limit)
            print("\n Choose a basis, pick a sigma and use the second mode!\n")

        except:
            print("""
@@ -737,6 +767,10 @@ def main():
            print(" GB1-------------------GB2-------------------Type----------"
                  "Number of Atoms ")
            print_list_GB_Planes(uvw, basis, m, n, lim)
            print(" \nPick a GB plane and customize the io_file! ")
            print(" then run : python gb_generator.py io_file\n ")



        except:
            print("Your input sigma is wrong!")
@@ -763,6 +797,8 @@ def main():
                  "Number of Atoms ")

            print_list_GB_Planes(uvw, basis, m, n, lim)
            print(" \nPick a GB plane and customize the io_file! ")
            print(" then run : python gb_generator.py io_file\n ")

        except:
            print("Your input sigma is wrong!")
+136 −38
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ class GB_character:
        self.overD = 0
        self.whichG = 'g1'
        self.trans = False
        self.File = 'LAMMPS'

    def ParseGB(self, axis, basis, LatP, m, n, gb):
        """
@@ -82,26 +83,40 @@ class GB_character:
            print("Sorry! For now only works for cubic lattices ... ")
            sys.exit()

<<<<<<< HEAD
    def WriteGB(self, *args):
        """
        parses the arguments and writes the final structure to the file.
        """
        self.overD = float(args[0])
=======
    def WriteGB(self, overlap=0.0, rigid=False,
                dim1=1, dim2=1, dim3=1, file='LAMMPS',
                **kwargs):
        """
        parses the arguments and writes the final structure to the file.
        Possible keys:
            (whichG, a, b)
        """
        self.overD = float(overlap)
        self.trans = rigid
        self.dim = np.array([int(dim1), int(dim2), int(dim3)])
        self.File = file
>>>>>>> development
        if self.overD > 0:
            self.whichG = str(args[1])
            self.trans = args[2]
            if self.trans:
                if len(args) != 8:
                    print('Make sure the input arguments are right!')
            try:
                self.whichG = kwargs['whichG']
            except:
                print('decide on whichG!')
                sys.exit()
                a = int(args[3])
                b = int(args[4])
                self.dim = np.array([int(args[5]), int(args[6]), int(args[7])])
            else:
                if len(args) != 6:
                    print('Make sure the input arguments are right!')
            if self.trans:
                try:
                    a = int(kwargs['a'])
                    b = int(kwargs['b'])
                except:
                    print('Make sure the a and b integers are there!')
                    sys.exit()
                self.dim = np.array([int(args[3]), int(args[4]), int(args[5])])

            xdel, ydel, x_indice, y_indice = self.Find_overlapping_Atoms()
            print ("<<------ {} atoms are being removed! ------>>"
                    .format(len(xdel)))
@@ -119,37 +134,48 @@ class GB_character:
            else:
                print("You must choose either 'g1', 'g2' ")
                sys.exit()

            self.Expand_Super_cell()

            if not self.trans:
                count = 0
                print ("<<------ 1 GB structure is being created! ------>>")
                if self.File == "LAMMPS":
                    self.Write_to_Lammps(count)
                elif self.File == "VASP":
                    self.Write_to_Vasp(count)
                else:
                    print("The output file must be either LAMMPS or VASP!")
            elif self.trans:
                self.Translate(a, b)

        elif self.overD == 0:
            self.trans = args[1]
            if self.trans:
                if len(args) != 7:
                    print('Make sure the input arguments are right!')
                try:
                    a = int(kwargs['a'])
                    b = int(kwargs['b'])
                except:
                    print('Make sure the a and b integers are there!')
                    sys.exit()
                print ("<<------ 0 atoms are being removed! ------>>")
                a = int(args[2])
                b = int(args[3])
                self.dim = np.array([int(args[4]), int(args[5]), int(args[6])])
                self.Expand_Super_cell()
                self.Translate(a, b)

            else:
<<<<<<< HEAD
                if len(args) != 5:
                    print('Make sure the input arguments are right!')
                    sys.exit()
                self.dim = np.array([int(args[2]), int(args[3]), int(args[4])])
=======
>>>>>>> development
                self.Expand_Super_cell()
                count = 0
                print ("<<------ 1 GB structure is being created! ------>>")
                if self.File == "LAMMPS":
                    self.Write_to_Lammps(count)
                elif self.File == "VASP":
                    self.Write_to_Vasp(count)
                else:
                    print("The output file must be either LAMMPS or VASP!")
        else:
            print('Overlap distance is not inputted incorrectly!')
            sys.exit()
@@ -289,7 +315,12 @@ class GB_character:
    def Translate(self, a, b ):

        """
<<<<<<< HEAD
        translates the GB on a mesh created by a, b integers and writes to LAMMPS.
=======
        translates the GB on a mesh created by a, b integers and writes
        to LAMMPS or VASP.
>>>>>>> development
        """
        tol = 0.001
        if (1 - cslgen.ang(self.gbplane, self.axis) < tol):
@@ -321,6 +352,8 @@ class GB_character:

        XX = self.atoms1
        count = 0
        if self.File == 'LAMMPS':

            for i in range(a):
                for j in range(b):
                    count += 1
@@ -328,7 +361,62 @@ class GB_character:
                    atoms1_new = XX.copy() + shift
                    self.atoms1 = atoms1_new
                    self.Write_to_Lammps(count)
        elif self.File == 'VASP':

            for i in range(a):
                for j in range(b):
                    count += 1
                    shift = i * shift1 + j * shift2
                    atoms1_new = XX.copy() + shift
                    self.atoms1 = atoms1_new
                    self.Write_to_Vasp(count)
        else:
            print("The output file must be either LAMMPS or VASP!")

<<<<<<< HEAD
=======
    def Write_to_Vasp(self, trans):
        """
        write a single GB without translations to POSCAR.
        """
        name = 'POS_G'
        plane = str(self.gbplane[0])+str(self.gbplane[1])+str(self.gbplane[2])
        if self.overD > 0:
            overD = str(self.overD)
        else:
            overD = str(None)
        Trans = str(trans)
        # tol = 0.001
        X = self.atoms1.copy()
        Y = self.atoms2.copy()
        X_new = X * self.LatP
        Y_new = Y * self.LatP
        dimx, dimy, dimz = self.dim

        xlo = -1 * np.round(norm(self.ortho1[:, 0]) * dimx * self.LatP, 8)
        xhi = np.round(norm(self.ortho1[:, 0]) * dimx * self.LatP, 8)
        LenX= xhi - xlo
        ylo = 0.0
        yhi = np.round(norm(self.ortho1[:, 1]) * dimy * self.LatP, 8)
        LenY= yhi - ylo
        zlo = 0.0
        zhi = np.round(norm(self.ortho1[:, 2]) * dimz * self.LatP, 8)
        LenZ = zhi - zlo

        Wf = np.concatenate((X_new, Y_new))

        with open(name + plane + '_' + overD + '_' +Trans, 'w') as f:
            f.write('#POSCAR written by GB_code \n')
            f.write('1 \n')
            f.write('{0:.8f} 0.0 0.0 \n'.format(LenX))
            f.write('0.0 {0:.8f} 0.0 \n'.format(LenY))
            f.write('0.0 0.0 {0:.8f} \n'.format(LenZ))
            f.write('{} {} \n'.format(len(X),len(Y)))
            f.write('Cartesian\n')
            np.savetxt(f, Wf, fmt='%.8f %.8f %.8f')
        f.close()

>>>>>>> development
    def Write_to_Lammps(self, trans):
        """
        write a single GB without translations to LAMMPS.
@@ -403,6 +491,7 @@ def main():
            a = in_params['a']
            b = in_params['b']
            dim1, dim2, dim3 = in_params['dimensions']
            file = in_params['File_type']

        except:
            print('Make sure the input argumnets in io_file are'
@@ -416,17 +505,26 @@ def main():
        gbI.CSL_Bicrystal_Atom_generator()

        if overlap > 0 and rigid:
            gbI.WriteGB(overlap, whichG, rigid, a, b, dim1, dim2, dim3)

            gbI.WriteGB(
                overlap = overlap, whichG = whichG, rigid = rigid, a = a,
                b = b, dim1 = dim1, dim2 = dim2, dim3 = dim3, file = file
                )
        elif overlap > 0 and not rigid:
            gbI.WriteGB(overlap, whichG, rigid, dim1, dim2, dim3)

            gbI.WriteGB(
                overlap = overlap, whichG = whichG, rigid = rigid,
                dim1 = dim1, dim2 = dim2, dim3 = dim3, file = file
                )
        elif overlap == 0 and rigid:
            gbI.WriteGB(overlap, rigid, a, b, dim1, dim2, dim3)

            gbI.WriteGB(
                overlap = overlap, rigid = rigid, a = a,
                b = b, dim1 = dim1, dim2 = dim2, dim3 = dim3,
                file = file
                )
        elif overlap == 0 and not rigid:
            gbI.WriteGB(overlap, rigid, dim1, dim2, dim3)

            gbI.WriteGB(
                overlap = overlap, rigid = rigid,
                dim1 = dim1, dim2 = dim2, dim3 = dim3, file = file
                )
    else:
        print(__doc__)
    return