예제 #1
0
def read_stresses_4visc(umdfile, short=0):
    niter = 0
    MyCrystal = cr.Lattice()
    AllSnapshots = []
    MySnapshot = cr.Lattice()
    with open(umdfile, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'timestep':
                    TimeStep = float(entry[1])
                if entry[0] == 'rprimd_a':
                    for ii in range(3):
                        MySnapshot.rprimd[0][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_b':
                    for ii in range(3):
                        MySnapshot.rprimd[1][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_c':
                    for ii in range(3):
                        MySnapshot.rprimd[2][ii] = float(entry[ii + 1])
                if entry[0] == 'Temperature':
                    MySnapshot.temperature = float(entry[1])
                if entry[0] == 'StressTensor':
                    MySnapshot.stress = [0.0 for x in range(6)]
                    for ii in range(6):
                        MySnapshot.stress[ii] = float(entry[ii + 1])

                if entry[0] == 'atoms:':
                    #print('current iteration no.',niter)
                    MySnapshot.cellvolume = MySnapshot.makevolume()
                    #print(MySnapshot.atoms[iatom].xcart[0])
                    AllSnapshots.append(MySnapshot)
                    if short == 1:
                        break  #if we selected the short option then we will stop to read the umd file after the first iteration
                    MySnapshot = cr.Lattice()
                    niter += 1
    #!!! remove first element from AllSnapshots
    print('len of allsnapshots is', len(AllSnapshots))
    return (AllSnapshots, TimeStep)
예제 #2
0
def main(argv):
    XYZfile='file.xyz'
    hh = 1
    vv = 1
    ww = 1
    natom = 0
    typat =[]
    Elements = []
    ballistic = 0
    TimeStep = 1
    umd.headerumd()
    try:
        opts, arg = getopt.getopt(argv,"hf:z:v:b:",["fumdfile","zHorizontalJump","vVerticalJump","bBallistic"])
    except getopt.GetoptError:
        print ('msd_umd.py -f <XYZ_filename> -z <HorizontalJump> -v <VerticalJump> -b <Ballistic>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print ('Program to compute the Mean Square Displacement. Usage: ')
            print ('msd_umd.py -f <UMD_filename> -z <HorizontalJump> -v <VerticalJump> -b <Ballistic>')
            print ('UMD_filename = input file with the trajectory, in UMD format.')
            print (' As the MSD is measured with a sliding window of various size up to half the trajectory\'s length, ')
            print (' we can accelerate the calculation using a selected reduced sampling ')
            print ('HorizontalJump = discretization for the start of the sampling window.')
            print ('VerticalJump = discretization for the length of the sampling window.')
            print ('Ballistic = estimation of the ballistic part of the trajectory. Default is 0. Typical values of 100 are sufficient.')
            sys.exit()
        elif opt in ("-f", "--fumdfile"):
            umdfile = str(arg)
            print ('I will use the ',umdfile,' for input')
        elif opt in ("-z", "--zHorizontalJump"):
            hh = int(arg)
        elif opt in ("-v", "--vVerticalJump"):
            vv = int(arg)
        elif opt in ("-b", "--bBallistic"):
            ballistic = int(arg)
    if (os.path.isfile(umdfile)):
#        initstruct(XYZfile)
        MyCrystal = cr.Lattice()
        AllSnapshots = [cr.Lattice]
        (MyCrystal,AllSnapshots,TimeStep)=umd.read_absxcart(umdfile)
#        (MyCrystal,AllSnapshots,TimeStep)=up.readumd(umdfile)
#        print 'Elements are ',elem
        print ('Number of atoms of each type is ',MyCrystal.types)
#        print 'Atomic types are ',znucl
        msd(MyCrystal,AllSnapshots,TimeStep,hh,vv,ballistic,umdfile)
    else:
        print ('umd file ',umdfile,'does not exist')
        sys.exit()
예제 #3
0
def main(argv):
    iterstep = 1
    firststep = 0
    laststep = 10000000
    UMDname = 'output.umd.dat'
    up.headerumd()
    try:
        opts, arg = getopt.getopt(argv, "hf:i:l:s:")
    except getopt.GetoptError:
        print(
            'umd2poscar.py -f <umdfile> -i <InitialStep> l <LastStep> -s <Sampling_Frequency>'
        )
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'umd2poscar.py program to extract POSCAR snapshots from the umd file'
            )
            print(
                'umd2poscar.py -f <umdfile> -i <InitialStep> l <LastStep> -s <Sampling_Frequency>'
            )
            print(' default values: -f output.umd.dat -i 0 -l 10000000 -s 1')
            sys.exit()
        elif opt in ("-f"):
            UMDname = str(arg)
        elif opt in ("-i"):
            firststep = int(arg)
        elif opt in ("-l"):
            laststep = int(arg)
        elif opt in ("-s"):
            iterstep = int(arg)
    if (os.path.isfile(UMDname)):
        print('The first ', firststep, 'timesteps will be discarded')
        print('The POSCAR file contains every ', iterstep, ' timesteps')
        MyCrystal = cr.Lattice()
        AllSnapshots = [cr.Lattice]
        (MyCrystal, AllSnapshots, TimeStep) = up.readumd(UMDname)
        if laststep > len(AllSnapshots):
            laststep = len(AllSnapshots)
        print_poscar(MyCrystal, AllSnapshots, UMDname, firststep, laststep,
                     iterstep)
    else:
        print('the umdfile ', umdfile, ' does not exist')
        sys.exit()
예제 #4
0
def read_bigheader_umd(umdfile, short=0):
    niter = 0
    MyCrystal = cr.Lattice()
    with open(umdfile, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'natom':
                    MyCrystal.natom = int(entry[1])
                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                if entry[0] == 'ntypat':
                    MyCrystal.ntypat = int(entry[1])
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                    MyCrystal.masses = [1.0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.zelec = [1.0 for _ in range(MyCrystal.ntypat)]
                if entry[0] == 'types':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.types[ii] = int(entry[ii + 1])
                if entry[0] == 'elements':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.elements[ii] = entry[ii + 1]
                if entry[0] == 'masses':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.masses[ii] = float(entry[ii + 1])
                if entry[0] == 'Zelectrons':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.zelec[ii] = float(entry[ii + 1])
                if entry[0] == 'typat':
                    for ii in range(MyCrystal.natom):
                        MyCrystal.typat[ii] = int(entry[ii + 1])
                if entry[0] == 'timestep':
                    TimeStep = float(entry[1])
                    break
    return (MyCrystal, TimeStep)
예제 #5
0
def main(argv):
    iterstep = 1
    firststep = 0
    UMDname = 'output.umd.dat'
    UMDname = ''
    up.headerumd()
    try:
        opts, arg = getopt.getopt(argv, "hf:i:n:")
    except getopt.GetoptError:
        print(
            'umd2xyz.py -f <umdfile> -i <InitialStep> -s <Sampling_Frequency>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'umd2xyz.py program to write an xyz file with the atomic trajectories from the umd file'
            )
            print(
                'umd2xyz.py -f <umdfile> -i <InitialStep> -s <Sampling_Frequency>'
            )
            print(' default values: -f output.umd.dat -i 0 -s 1')
            sys.exit()
        elif opt in ("-f"):
            UMDname = str(arg)
        elif opt in ("-i"):
            firststep = int(arg)
        elif opt in ("-n"):
            iterstep = int(arg)
    if (os.path.isfile(UMDname)):
        print('The first ', firststep, 'timesteps will be discarded')
        print('The XYZ file contains every ', iterstep, ' timesteps')
        MyCrystal = cr.Lattice()
        AllSnapshots = [cr.Lattice]
        (MyCrystal, AllSnapshots, TimeStep) = up.readumd(UMDname)
        print_xyz(MyCrystal, AllSnapshots, UMDname, firststep, iterstep)
    else:
        print('the umdfile ', umdfile, ' does not exist')
        sys.exit()
예제 #6
0
def read_umd(umdfile, radius, Nsteps, InitialStep, level):
    """Read umd file and store data into classes """
    umd.headerumd()
    niter = 0
    istep = 0
    MyCrystal = cr.Lattice()
    with open(
            umdfile, 'r'
    ) as ff:  #read the head and half of the 1st iter in order to get acell
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'natom':
                    MyCrystal.natom = int(entry[1])
                    #print('natom=',MyCrystal.natom)
                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                if entry[0] == 'ntypat':
                    MyCrystal.ntypat = int(entry[1])
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                if entry[0] == 'types':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.types[ii] = int(entry[ii + 1])
                if entry[0] == 'elements':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.elements[ii] = entry[ii + 1]
                if entry[0] == 'typat':
                    for ii in range(MyCrystal.natom):
                        MyCrystal.typat[ii] = int(entry[ii + 1])
                if entry[0] == 'acell':
                    for i in range(3):
                        MyCrystal.acell[i] = float(entry[i + 1])
    newfile = print_header(umdfile, MyCrystal, radius)  #create the new file
    with open(umdfile,
              'r') as ff:  #read the entire file to get the atomic positions
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'atoms:':
                    istep += 1
                    #print('current iteration no.',istep)
                    MySnapshot = cr.Lattice()
                    MySnapshot.atoms = [
                        cr.Atom() for _ in range(MyCrystal.natom)
                    ]
                    for iatom in range(MyCrystal.natom):
                        line = ff.readline()
                        line = line.strip()
                        entry = line.split()
                        for jj in range(3):
                            MySnapshot.atoms[iatom].xcart[jj] = float(
                                entry[jj + 3])
                        #print(MySnapshot.atoms[iatom].xcart[0])
                    if istep > InitialStep:
                        if niter % Nsteps == 0:  #if the remainder of niter/Nsteps is 0, then I compute the dmin
                            #print (' at step ',istep,' I am calling dmin ')
                            dmin = computealldmin(MyCrystal, MySnapshot)
                            overlap = computeoverlap(dmin, radius, MyCrystal)
                            print_overlap(newfile, overlap, dmin, istep,
                                          MyCrystal, radius, level)
                        niter += 1
예제 #7
0
def read_xcart(umdfile, short=0):
    niter = 0
    MyCrystal = cr.Lattice()
    AllSnapshots = []
    MySnapshot = cr.Lattice()
    with open(umdfile, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'natom':
                    MyCrystal.natom = int(entry[1])
                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                if entry[0] == 'ntypat':
                    MyCrystal.ntypat = int(entry[1])
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                    MyCrystal.masses = [1.0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.zelec = [1.0 for _ in range(MyCrystal.ntypat)]
                if entry[0] == 'types':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.types[ii] = int(entry[ii + 1])
                if entry[0] == 'elements':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.elements[ii] = entry[ii + 1]
                if entry[0] == 'masses':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.masses[ii] = float(entry[ii + 1])
                if entry[0] == 'Zelectrons':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.zelec[ii] = float(entry[ii + 1])
                if entry[0] == 'typat':
                    for ii in range(MyCrystal.natom):
                        MyCrystal.typat[ii] = int(entry[ii + 1])
                if entry[0] == 'timestep':
                    TimeStep = float(entry[1])
                if entry[0] == 'acell':
                    for ii in range(3):
                        MySnapshot.acell[ii] = float(entry[ii + 1])
                if entry[0] == 'acell':
                    for ii in range(3):
                        MySnapshot.acell[ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_a':
                    for ii in range(3):
                        MySnapshot.rprim[0][ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_b':
                    for ii in range(3):
                        MySnapshot.rprim[1][ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_c':
                    for ii in range(3):
                        MySnapshot.rprim[2][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_a':
                    for ii in range(3):
                        MySnapshot.rprimd[0][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_b':
                    for ii in range(3):
                        MySnapshot.rprimd[1][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_c':
                    for ii in range(3):
                        MySnapshot.rprimd[2][ii] = float(entry[ii + 1])

                if entry[0] == 'atoms:':
                    #print('current iteration no.',niter)
                    MySnapshot.atoms = [
                        cr.Atom() for _ in range(MyCrystal.natom)
                    ]
                    for iatom in range(MyCrystal.natom):
                        line = ff.readline()
                        line = line.strip()
                        entry = line.split()
                        for jj in range(3):
                            MySnapshot.atoms[iatom].xcart[jj] = float(
                                entry[jj + 3])
                    #print(MySnapshot.atoms[iatom].xcart[0])
                    AllSnapshots.append(MySnapshot)
                    if short == 1:
                        break  #if we selected the short option then we will stop to read the umd file after the first iteration
                    MySnapshot = cr.Lattice()
                    niter += 1
    #!!! remove first element from AllSnapshots
    print('len of allsnapshots is', len(AllSnapshots))
    return (MyCrystal, AllSnapshots, TimeStep)
예제 #8
0
def read_header_snapshots(umdfile, short=0):
    niter = 0
    AllSnapshots = []
    MySnapshot = cr.Lattice()
    with open(umdfile, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'natom':
                    MyCrystal.natom = int(entry[1])
                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                if entry[0] == 'ntypat':
                    MyCrystal.ntypat = int(entry[1])
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                    MyCrystal.masses = [1.0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.zelec = [1.0 for _ in range(MyCrystal.ntypat)]
                if entry[0] == 'types':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.types[ii] = int(entry[ii + 1])
                if entry[0] == 'elements':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.elements[ii] = entry[ii + 1]
                if entry[0] == 'masses':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.masses[ii] = float(entry[ii + 1])
                if entry[0] == 'Zelectrons':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.zelec[ii] = float(entry[ii + 1])
                if entry[0] == 'typat':
                    for ii in range(MyCrystal.natom):
                        MyCrystal.typat[ii] = int(entry[ii + 1])
                if entry[0] == 'timestep':
                    TimeStep = float(entry[1])
                if entry[0] == 'acell':
                    for ii in range(3):
                        MySnapshot.acell[ii] = float(entry[ii + 1])
                if entry[0] == 'acell':
                    for ii in range(3):
                        MySnapshot.acell[ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_a':
                    for ii in range(3):
                        MySnapshot.rprim[0][ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_b':
                    for ii in range(3):
                        MySnapshot.rprim[1][ii] = float(entry[ii + 1])
                if entry[0] == 'rprim_c':
                    for ii in range(3):
                        MySnapshot.rprim[2][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_a':
                    for ii in range(3):
                        MySnapshot.rprimd[0][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_b':
                    for ii in range(3):
                        MySnapshot.rprimd[1][ii] = float(entry[ii + 1])
                if entry[0] == 'rprimd_c':
                    for ii in range(3):
                        MySnapshot.rprimd[2][ii] = float(entry[ii + 1])

                if entry[0] == 'atoms:':
                    AllSnapshots.append(MySnapshot)
    return (MyCrystal, AllSnapshots, TimeStep)
예제 #9
0
def read_umd(umdfile, Nsteps, discrete, InitialStep):
    """Read umd file and store data into classes """
    niter = 0
    istep = 0
    MyCrystal = cr.Lattice()
    with open(
            umdfile, 'r'
    ) as ff:  #read the head and half of the 1st iter in order to get acell
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'natom':
                    MyCrystal.natom = int(entry[1])
                    print('natom=', MyCrystal.natom)
                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                if entry[0] == 'ntypat':
                    MyCrystal.ntypat = int(entry[1])
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                if entry[0] == 'types':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.types[ii] = int(entry[ii + 1])
                if entry[0] == 'elements':
                    for ii in range(MyCrystal.ntypat):
                        MyCrystal.elements[ii] = entry[ii + 1]
                if entry[0] == 'typat':
                    for ii in range(MyCrystal.natom):
                        MyCrystal.typat[ii] = int(entry[ii + 1])
                if entry[0] == 'acell':
                    for i in range(3):
                        MyCrystal.acell[i] = float(entry[i + 1])
                    maxlength = min(MyCrystal.acell[0], MyCrystal.acell[1],
                                    MyCrystal.acell[2])
    ndivx = int(maxlength / (2 * discrete))
    print('acell', MyCrystal.acell[0], 'discrete', discrete, 'ndivx ', ndivx)
    gofr = [[[0 for kk in range(ndivx + 1)]
             for jatom in range(MyCrystal.ntypat)]
            for iatom in range(MyCrystal.ntypat)]
    with open(umdfile,
              'r') as ff:  #read the entire file to get the atomic positions
        while True:
            line = ff.readline()
            if not line: break
            #print(line,len(line))
            if len(line) > 1:
                line = line.strip()
                entry = line.split()
                if entry[0] == 'atoms:':
                    istep += 1
                    #print('current iteration no.',istep)
                    MySnapshot = cr.Lattice()
                    MySnapshot.atoms = [
                        cr.Atom() for _ in range(MyCrystal.natom)
                    ]
                    for iatom in range(MyCrystal.natom):
                        line = ff.readline()
                        line = line.strip()
                        entry = line.split()
                        for jj in range(3):
                            MySnapshot.atoms[iatom].xcart[jj] = float(
                                entry[jj + 3])
                        #print(MySnapshot.atoms[iatom].xcart[0])
                    if istep > InitialStep:
                        if niter % Nsteps == 0:  #if the remainder of niter/Nsteps is 0, then I compute the gofr
                            #print (' at step ',istep,' I am calling gofr ')
                            gofr = computeallgofr(MyCrystal, MySnapshot,
                                                  discrete, maxlength, gofr)
                        niter += 1
    normalization = niter / Nsteps  #number of time steps actually used in the calculation of gofr
    print_gofrs(umdfile, MyCrystal, ndivx, discrete, normalization, maxlength,
                gofr)
예제 #10
0
def main(argv):
    up.headerumd()
    UMDname = 'output.umd.dat'
    Nsteps = 1
    InitialStep = 0
    ClusterAtoms = []
    Cations = []
    Anions = []
    maxlength = 3.0
    InputFile = ''
    minlife = 5
    rings = 1
    header = ''
    try:
        opts, arg = getopt.getopt(argv, "hf:s:l:c:a:m:i:r:", [
            "fUMDfile", "sSampling_Frequency", "lMaxLength", "cCations",
            "aAnions", "mMinlife", "iInputFile", "rRings"
        ])
    except getopt.GetoptError:
        print(
            'speciation.py -f <UMD_filename> -s <Sampling_Frequency> -l <MaxLength> -c <Cations> -a <Anions> -m <MinLife> -i <InputFile> -r <Rings>'
        )
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'speciation.py program to compute bonding maps and identify speciation'
            )
            print(
                'speciation.py -f <UMD_filename> -s <Sampling_Frequency> -l <MaxLength> -c <Cations> -a <Anions> -m <MinLife>  -i <InputFile> -r <Rings>'
            )
            print('  default values: -f output.umd.dat -s 1 -l 3.0 -m 0 -r 1')
            print(
                ' the input file contains the bond lengths for the different atom pairs. \n the values overwrite the option -l'
            )
            print(
                ' rings = 1 default, polymerization, all anions and cations bond to each other; rings = 0 only individual cation-anion groups'
            )
            sys.exit()
        elif opt in ("-f", "--fUMDfile"):
            UMDname = str(arg)
            header = header + 'FILE: -f=' + UMDname
        elif opt in ("-s", "--sNsteps"):
            Nsteps = int(arg)
            header = header + ' -s=' + arg
            print('Will sample the MD trajectory every ', Nsteps, ' steps')
        elif opt in ("-l", "--lMaxLength"):
            maxlength = float(arg)
            print('Maximum bonding length is', maxlength)
            header = header + ' -l=' + str(maxlength)
        elif opt in ("-m", "--mMinlife"):
            minlife = float(arg)
        elif opt in ("-c", "--Cations"):
            header = header + arg
            Cations = arg.split(",")
            #print ('Cation list is: ',Cations)
        elif opt in ("-a", "--Anions"):
            header = header + arg
            Anions = arg.split(",")
            #print ('Anion list is: ',Anions)
        elif opt in ("-i", "--iInputFile"):
            InputFile = str(arg)
            header = header + ' -i=' + InputFile
            print('Bonding cutoffs to be read from file ', InputFile)
        elif opt in ("-r", "--rRings"):
            rings = int(arg)
            header = header + ' -r=' + arg
            if rings == 0:
                print('Calculation of non-polymerized coordination polyhedra')
            elif rings == 1:
                print('Calculation of polymerized coordination')
            else:
                print('Undefined calculation')

    if not (os.path.isfile(UMDname)):
        print('the UMD files ', UMDname, ' does not exist')
        sys.exit()

    for ii in range(len(Cations)):
        ClusterAtoms.append(Cations[ii])
    for ii in range(len(Anions)):
        ClusterAtoms.append(Anions[ii])
    if rings == 0:
        print('searching for cations', Cations)
        print('surrounded by anions ', Anions)
    else:
        print('all atoms bonding:', ClusterAtoms)

#writes the header of the files containing eventually the clusters
    header = header + '\n'
    FileAll = UMDname + '.r' + str(rings) + '.popul.dat'
    print('Population will be written in ', FileAll, ' file')
    fa = open(FileAll, 'w')
    fa.write(header)
    fa.close()
    FileStat = UMDname + '.r' + str(rings) + '.stat.dat'
    print('Statistics will be written in ', FileStat, ' file')
    fa = open(FileStat, 'w')
    fa.write(header)
    fa.close()

    #reading the xc art coordinates of the atoms from the UMD file. it uses the read_xcart (i.e. only xcart) function from the umd_process library
    MyCrystal = cr.Lattice()
    AllSnapshots = [cr.Lattice]
    (MyCrystal, AllSnapshots, TimeStep) = up.read_xcart(UMDname)
    #print('checks after reading the umd file')
    #print('no of atoms = ',MyCrystal.natom)

    #reading the cutoff radii for the bonds
    BondTable = [[maxlength * maxlength for _ in range(MyCrystal.ntypat)]
                 for _ in range(MyCrystal.ntypat)]
    if len(InputFile) > 0:
        BondTable = read_inputfile(InputFile, MyCrystal, ClusterAtoms)
#print ('unique bondlength, with square',maxlength)

#defining the ligands, the coordinated and the coordinating atoms
    centralatoms = []
    outeratoms = []
    ligands = []
    for iatom in range(MyCrystal.natom):
        for jatom in range(len(ClusterAtoms)):
            if MyCrystal.elements[
                    MyCrystal.typat[iatom]] == ClusterAtoms[jatom]:
                ligands.append(
                    iatom
                )  #contains the list with the index of the ligand atoms from the 0 ... natom
    for iatom in range(MyCrystal.natom):
        for jatom in range(len(Cations)):
            if MyCrystal.elements[MyCrystal.typat[iatom]] == Cations[jatom]:
                centralatoms.append(
                    iatom
                )  #contains the list with the index of the central atoms from the 0 ... natom
        for jatom in range(len(Anions)):
            if MyCrystal.elements[MyCrystal.typat[iatom]] == Anions[jatom]:
                outeratoms.append(
                    iatom
                )  #contains the list with the index of the coordinating atoms from the 0 ... natom
    print('All ligands are: ', ligands)
    print('Central atoms are :', centralatoms)
    print('Coordinating atoms are :', outeratoms)

    #span the entire trajectory and analyze only the Nsteps snapshots
    clusters = []
    for istep in range(0, len(AllSnapshots), Nsteps):
        #print('analyzing new simulation snapshot, step no. ',istep)
        #first build the bonding maps
        BondMap = [[0.0 for _ in range(MyCrystal.natom)]
                   for _ in range(MyCrystal.natom)]
        BooleanMap = [[0 for _ in range(MyCrystal.natom)]
                      for _ in range(MyCrystal.natom)]
        (BondMap, BooleanMap) = ComputeBondMapInput(MyCrystal,
                                                    AllSnapshots[istep],
                                                    ligands, BondTable)
        if rings == 1:
            clusters.append(clustering(BooleanMap, ligands))
        elif rings == 0:
            clusters.append(
                clusteringnorings(BooleanMap, centralatoms, outeratoms))
        #print('number of identified clusters ',len(clusters))
        #print(' clusters at this point:\n',clusters)
        else:
            print(
                'value of rings = ',
                rings,
                ' is not allowed. Only 0 (polymers) or 1 (coordinating polyhedra) are allowed',
            )
            sys.exit()
    analysis_clusters(clusters, MyCrystal, ligands, minlife, Nsteps, UMDname,
                      rings)
예제 #11
0
def read_qbox(FileName, InitialStep, SYSfile):
    #read poscar file
    print('reading output file ', FileName)
    print('initializing structure from file ', SYSfile)
    print('discarding ', InitialStep, ' initial steps')
    GPaAcube = 1 / ((0.529177249**3) * 29421.033 * 27.21138602)
    BohrtoAng = 0.5291772
    switch = False
    flagrprimd = -1
    flagstart = 0
    iatom = -1
    istep = 0
    titleflag = 0
    MyCrystal = cr.Lattice()
    TimeStep = 1.0
    newfile = FileName + '.umd.dat'
    atomname = ''
    nf = open(newfile, 'w')
    nf.close()
    MyCrystal.elements = []
    MyCrystal.natom = 0
    MyCrystal.ntypat = 0
    MyCrystal.types = []
    MyCrystal.typat = []
    if SYSfile == '':
        structName = FileName
        indexatom = 1
    else:
        structName = SYSfile
        indexatom = 0
    print('reading structure from', structName)
    with open(structName, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            #print('new line is ',line)
            line = line.strip()
            entry = line.split()
            if (len(entry) > 1):
                #print('with entry[1] is ',entry[1])
                if (entry[indexatom] == 'atom'):  #determine how many atoms
                    #print(' ')
                    #jatom = 0
                    MyCrystal.natom = MyCrystal.natom + 1
                    #print('total number of atoms so far is',MyCrystal.natom,' with current atom ',entry[2])
                    atomname = ''.join(
                        [kk for kk in entry[1] if not kk.isdigit()])
                    #print ('newly renamed atom is ',atomname)
                    flagexistentatom = 0
                    if len(MyCrystal.elements) > 0:
                        #print('the list of elements is not empty, but contains already ',len(MyCrystal.elements),' elements :',MyCrystal.elements)
                        for jj in range(len(MyCrystal.elements)):
                            #print ('  atomname ',atomname,'to be compared with type no. ',jj,' which is ',MyCrystal.elements[jj])
                            if atomname == MyCrystal.elements[jj]:
                                flagexistentatom = 1
                                indexoftype = jj
                        if flagexistentatom == 0:
                            MyCrystal.elements.append(atomname)
                            #print('new version of mycrystal.elements', MyCrystal.elements)
                            MyCrystal.types.append(1)
                            MyCrystal.ntypat = MyCrystal.ntypat + 1
                            #print('    newly added atom. ')
                            #print('    at this point elements are: ',MyCrystal.elements)
                            #print('    current atom list with ntypat ',MyCrystal.ntypat,' and types ',MyCrystal.types)
                        else:
                            #print('    element already existent ',MyCrystal.elements[jj],' with index no. ',indexoftype)
                            MyCrystal.types[indexoftype] += 1
                    else:
                        #print ('adding first element to the empty list', MyCrystal.elements)
                        MyCrystal.elements.append(atomname)
                        #print('first version of atomic types', MyCrystal.elements)
                        MyCrystal.ntypat = MyCrystal.ntypat + 1
                        MyCrystal.types = [1]
                        #print('current ntypat and types ',MyCrystal.ntypat,MyCrystal.types)
                if (entry[1] == '</wavefunction>'):
                    break
                if (entry[1] == 'End'):
                    break
    ff.close()
    MyCrystal.typat = [0 for i in range(MyCrystal.natom)]
    iatom = 0
    for itypat in range(MyCrystal.ntypat):
        for itypes in range(MyCrystal.types[itypat]):
            MyCrystal.typat[iatom] = itypat
            iatom += 1

    print('MyCrystal has been initiliazed as: ')
    MyCrystal.atoms = [cr.Atom() for _ in range(MyCrystal.natom)]
    oldpos = [[0.0, 0.0, 0.0] for _ in range(MyCrystal.natom)]
    print('natom = ', MyCrystal.natom)
    print('ntypat = ', MyCrystal.ntypat)
    print('types = ', MyCrystal.types)
    print('elements = ', MyCrystal.elements)
    print_header(FileName, MyCrystal)

    with open(FileName, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            line = line.strip()
            entry = line.split()
            if len(entry) == 4:
                #print('line with four entries ',line)
                if entry[2] == 'dt':
                    TimeStep = float(entry[3]) * 0.02418884326505
                    #print('timestep is',TimeStep)
            if len(entry) == 2:
                if entry[0] == '<iteration':
                    counter = entry[1].split("\"")
                    flagstart += 1
            if flagstart > InitialStep and len(entry) > 0:
                if entry[0] == '<sigma_xx>':
                    MyCrystal.stress[0] = float(entry[1])
                if entry[0] == '<sigma_yy>':
                    MyCrystal.stress[1] = float(entry[1])
                if entry[0] == '<sigma_zz>':
                    MyCrystal.stress[2] = float(entry[1])
                    MyCrystal.pressure = (MyCrystal.stress[0] +
                                          MyCrystal.stress[1] +
                                          MyCrystal.stress[2]) / 3.0
                if entry[0] == '<sigma_yz>':
                    MyCrystal.stress[3] = float(entry[1])
                if entry[0] == '<sigma_xz>':
                    MyCrystal.stress[4] = float(entry[1])
                if entry[0] == '<sigma_xy>':
                    MyCrystal.stress[5] = float(entry[1])
                if entry[0] == '<temp_ion>':
                    MyCrystal.temperature = float(entry[1])
                if entry[0] == '<etotal>':
                    MyCrystal.internalenergy = float(entry[1])
                if entry[0] == 'a=\"':
                    MyCrystal.rprimd[0][0] = float(entry[1]) * BohrtoAng
                    MyCrystal.rprimd[0][1] = float(entry[2]) * BohrtoAng
                    MyCrystal.rprimd[0][2] = float(entry[3][:-1]) * BohrtoAng
                    MyCrystal.acell[0] = math.sqrt(MyCrystal.rprimd[0][0]**2 +
                                                   MyCrystal.rprimd[0][1]**2 +
                                                   MyCrystal.rprimd[0][2]**2)
                    MyCrystal.rprim[0][
                        0] = MyCrystal.rprimd[0][0] / MyCrystal.acell[0]
                    MyCrystal.rprim[0][
                        1] = MyCrystal.rprimd[0][1] / MyCrystal.acell[0]
                    MyCrystal.rprim[0][
                        2] = MyCrystal.rprimd[0][2] / MyCrystal.acell[0]
                if entry[0] == 'b=\"':
                    MyCrystal.rprimd[1][0] = float(entry[1]) * BohrtoAng
                    MyCrystal.rprimd[1][1] = float(entry[2]) * BohrtoAng
                    MyCrystal.rprimd[1][2] = float(entry[3][:-1]) * BohrtoAng
                    MyCrystal.acell[1] = math.sqrt(MyCrystal.rprimd[1][0]**2 +
                                                   MyCrystal.rprimd[1][1]**2 +
                                                   MyCrystal.rprimd[1][2]**2)
                    MyCrystal.rprim[1][
                        0] = MyCrystal.rprimd[1][0] / MyCrystal.acell[1]
                    MyCrystal.rprim[1][
                        1] = MyCrystal.rprimd[1][1] / MyCrystal.acell[1]
                    MyCrystal.rprim[1][
                        2] = MyCrystal.rprimd[1][2] / MyCrystal.acell[1]
                if entry[0] == 'c=\"':
                    MyCrystal.rprimd[2][0] = float(entry[1]) * BohrtoAng
                    MyCrystal.rprimd[2][1] = float(entry[2]) * BohrtoAng
                    MyCrystal.rprimd[2][2] = float(entry[3][:-1]) * BohrtoAng
                    MyCrystal.acell[2] = math.sqrt(MyCrystal.rprimd[2][0]**2 +
                                                   MyCrystal.rprimd[2][1]**2 +
                                                   MyCrystal.rprimd[2][2]**2)
                    MyCrystal.rprim[2][
                        0] = MyCrystal.rprimd[2][0] / MyCrystal.acell[2]
                    MyCrystal.rprim[2][
                        1] = MyCrystal.rprimd[2][1] / MyCrystal.acell[2]
                    MyCrystal.rprim[2][
                        2] = MyCrystal.rprimd[2][2] / MyCrystal.acell[2]
                    #print('rprimd is',MyCrystal.rprimd)
                    MyCrystal.cellvolume = MyCrystal.makevolume()
                    #print('cellvolume is',MyCrystal.cellvolume)
                    MyCrystal.gprimd = MyCrystal.makegprimd()
                    MyCrystal.cellvolume = MyCrystal.makevolume()
                    #print('cellvolume is',MyCrystal.cellvolume)
                if entry[0] == '<atomset>':
                    jatom = -1
                if entry[0] == '<position>':
                    jatom += 1
                    MyCrystal.atoms[jatom].absxcart[0] = float(
                        entry[1]) * BohrtoAng
                    MyCrystal.atoms[jatom].absxcart[1] = float(
                        entry[2]) * BohrtoAng
                    MyCrystal.atoms[jatom].absxcart[2] = float(
                        entry[3]) * BohrtoAng
                    #MyCrystal.atoms[jatom].xred = MyCrystal.absxcart2xred(MyCrystal.atoms[jatom].absxcart)
                    #MyCrystal.atoms[jatom].xcart = MyCrystal.absxred2xcart(MyCrystal.atoms[jatom].xred)
                if entry[0] == '<velocity>':
                    MyCrystal.atoms[jatom].vels[0] = float(entry[1])
                    MyCrystal.atoms[jatom].vels[1] = float(entry[2])
                    MyCrystal.atoms[jatom].vels[2] = float(entry[3])
                if entry[0] == '<force>':
                    MyCrystal.atoms[jatom].forces[0] = float(entry[1])
                    MyCrystal.atoms[jatom].forces[1] = float(entry[2])
                    MyCrystal.atoms[jatom].forces[2] = float(entry[3])
                if entry[0] == '</iteration>':
                    MyCrystal.enthalpy = MyCrystal.internalenergy + MyCrystal.pressure * MyCrystal.cellvolume * GPaAcube
                    MyCrystal.allabsxcart2xred()
                    MyCrystal.allxred2xcart()
                    print_umd(FileName, MyCrystal, TimeStep,
                              (flagstart - InitialStep) * TimeStep)
    return (CurrentTime, TimeStep)
예제 #12
0
def read_outcar(FileName, InitialStep):
    #read poscar file
    print('Reading outcar file ', FileName, ' from initial step ', InitialStep)
    switch = False
    flagrprimd = -1
    iatom = -1
    istep = 0
    MyCrystal = cr.Lattice()
    TimeStep = 1.0
    newfile = FileName + '.umd.dat'
    nf = open(newfile, 'w')
    nf.close()
    atomictype = 0
    CurrentTime = 0.0
    TimeStep = 0.0
    with open(FileName, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            line = line.strip()
            entry = line.split()
            if (len(entry) > 0):
                if (entry[0] == 'ions'):  #determine how many atoms
                    jatom = 0
                    MyCrystal.natom = 0
                    MyCrystal.ntypat = len(entry) - 4
                    MyCrystal.types = [0 for _ in range(MyCrystal.ntypat)]
                    for ii in range(len(entry) - 4):
                        MyCrystal.natom = MyCrystal.natom + int(entry[4 + ii])
                        MyCrystal.types[ii] = int(entry[4 + ii])

                    MyCrystal.typat = [0 for _ in range(MyCrystal.natom)]
                    for ii in range(len(entry) - 4):
                        atomictype += 1
                        for jj in range(int(entry[4 + ii])):
                            MyCrystal.typat[jatom] = atomictype - 1
                            jatom = jatom + 1
                    MyCrystal.atoms = [
                        cr.Atom() for _ in range(MyCrystal.natom)
                    ]
                    oldpos = [cr.Atom() for _ in range(MyCrystal.natom)]
                    MyCrystal.elements = ['X' for _ in range(MyCrystal.ntypat)]
                    MyCrystal.masses = [0.0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.zelec = [0.0 for _ in range(MyCrystal.ntypat)]
                    MyCrystal.stress = [0.0 for _ in range(6)]
                    phase = [[0.0, 0.0, 0.0] for _ in range(MyCrystal.natom)]
                    diffcoords = [[0.0, 0.0, 0.0]
                                  for _ in range(MyCrystal.natom)]
                    MyCrystal.magnetization = 0.0
                    print('Total number of atoms = ', len(diffcoords))
                    break
    ff.close()
    flagmass = 0
    flagtitle = 0
    atn = ''
    ats = ''
    atno = ''
    with open(FileName, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            line = line.strip()
            entry = line.split()
            if (len(entry) > 0):
                if (len(entry) > 1):
                    if entry[1] == 'Iteration':
                        break
#                if (entry[0]=='VRHFIN'):
#                    flagtitle += 1
#                    atomicsymbol = entry[1]
#                    MyCrystal.elements[flagtitle-1] = atomicsymbol[1:-1]
#                    print ('element ',flagtitle,' is ',MyCrystal.elements[flagtitle-1])
#                    (atn,ats,atno,MyCrystal.masses[flagtitle-1])=cr.Elements2rest(MyCrystal.elements[flagtitle-1])
#                    print ('just chekcing: ',atn,ats,atno)
                if (entry[0] == 'POTCAR:'):
                    if (flagtitle < MyCrystal.ntypat):
                        MyCrystal.elements[flagtitle] = entry[2].split('_')[0]
                        #                        print ('element ',flagtitle,' is ',MyCrystal.elements[flagtitle])
                        (atn, ats, atno,
                         MyCrystal.masses[flagtitle]) = cr.Elements2rest(
                             MyCrystal.elements[flagtitle])
                        #                        print ('just chekcing: ',atn,ats,atno)
                        print('element ', flagtitle, ' is ',
                              MyCrystal.elements[flagtitle],
                              ' with atomic number ', atno, ' and mass ',
                              MyCrystal.masses[flagtitle])
                        flagtitle += 1
                if (entry[0] == 'POMASS'):
                    if flagmass < MyCrystal.ntypat:
                        #                        print('flagmass is',flagmass,' with the line ',entry)
                        #                        for ii in range(MyCrystal.ntypat):
                        MyCrystal.masses[flagmass] = float(entry[2][:-1])
                        MyCrystal.zelec[flagmass] = float(entry[5])
                        flagmass += 1
#                if (entry[0]=='ZVAL'):
#                    for ii in range(MyCrystal.ntypat):
#                        MyCrystal.zelec[ii]=float(entry[ii+2])
#                if (entry[0]=='Mass'):
#                    flagmass=1
                if (entry[0] == 'NELECT'):
                    MyCrystal.noelectrons = float(entry[2])

    ff.close()
    umd.print_header(FileName, MyCrystal)
    with open(FileName, 'r') as ff:
        while True:
            line = ff.readline()
            if not line: break
            line = line.strip()
            entry = line.split()
            if (len(entry) == 6):
                #                print ('a line of 6 elements: ',entry)
                if (entry[4] == 'magnetization'):
                    #                    print ('the line of 6 elements: ',entry)
                    MyCrystal.magnetization = float(entry[5])
            if (switch == False):
                if (len(entry) > 0 and entry[0] == 'POTIM'):
                    TimeStep = float(entry[2])
                if (len(entry) >= 2 and entry[1] == 'aborting'):
                    switch = True
                else:
                    continue
            if (switch == True and len(entry) > 0):
                #                print 'entry[0] is ',entry[0]
                jatom = 0
                if (
                        entry[0] == 'Total+kin.'
                ):  #reading stress tensor, corrected for the internal kinetic pressure (the term contains it itself0
                    for ii in range(6):
                        MyCrystal.stress[ii] = float(
                            entry[ii +
                                  1]) / 10.0  #transforms from kbars into GPa
                    MyCrystal.pressure = (
                        float(entry[1]) + float(entry[2]) + float(entry[3])
                    ) / 30.0  #transforms also from kbars into GPa
                if entry[0] == 'energy':
                    if entry[
                            2] == 'entropy=':  #reading Kohn-Sham energy, contains all the electronic energy without the electronic entropy
                        MyCrystal.internalenergy = float(
                            entry[3]
                        )  #this leads only part of the internal energy, one should add the kinetic energy of ions
                        #the variance of {this energy + kinetic energy of ions}  yields Cv
                if (entry[0] == '%'):
                    if (
                            entry[1] == 'ion-electron'
                    ):  #the term T*Sel in the formula F = E - T*Sel, with F = Kohn-Sham energy and E = Kohn-Sham energy without the electronic entropy
                        MyCrystal.electronicentropy = MyCrystal.internalenergy - float(
                            entry[4])
                if (entry[0] == 'magnetization'
                    ):  #reading magnetization of individual atoms
                    #print('reading magnetization')
                    line = ff.readline()
                    line = ff.readline()
                    line = ff.readline()
                    for ii in range(MyCrystal.natom):
                        line = ff.readline()
                        line = line.strip()
                        entry = line.split()
                        MyCrystal.atoms[ii].magnet = float(entry[len(entry) -
                                                                 1])
                        #print ('for atom ',iatom,' magnetization is ',MyCrystal.atoms[ii].magnet)


#                if (len(entry) == 6):
#                    print ('a line of 6 elements: ',entry)
#                    if (entry[0] == 'number'):
#                        print ('the line of 6 elements: ',entry)
#                        MyCrystal.magnetization = float(entry[5])
                if line == 'total charge':  #reading the atomi charges
                    #print('reading magnetization')
                    line = ff.readline()
                    line = ff.readline()
                    line = ff.readline()
                    for ii in range(MyCrystal.natom):
                        line = ff.readline()
                        line = line.strip()
                        entry = line.split()
                        MyCrystal.atoms[ii].charge = float(entry[len(entry) -
                                                                 1])
                if (entry[0] == 'kinetic'):  #reading kinetic energy of ions
                    if (len(entry) > 2):
                        if (entry[2] == 'EKIN'):
                            MyCrystal.kineticenergy = float(entry[4])
                if (entry[0] == 'total'):  #reading energy
                    #KS energy + thermostat + ion-kinetic terms
                    #used to check the drift in energy over a simulation
                    if (len(entry) > 2):
                        if (entry[2] == 'ETOTAL'):
                            MyCrystal.energywithdrift = float(entry[4])
                            #ETOTAL is the last value we want to take in the umd, so we can put the switch off and increase the counter of steps
                            #Once istep >= InitialStep, we can compute the velocities, diffcoord etc. and print the umd
                            switch = False
                            istep = istep + 1
                            if istep >= InitialStep:
                                #print (' treating step no. ', istep)
                                for jatom in range(MyCrystal.natom):
                                    for ii in range(3):
                                        jump = MyCrystal.atoms[jatom].xcart[
                                            ii] - oldpos[jatom].xcart[ii]
                                        if jump > MyCrystal.acell[ii] / 2:
                                            #print ('positive jump',jump,jatom,MyCrystal.atoms[jatom].xcart[ii],oldpos[jatom].xcart[ii])
                                            phase[jatom][
                                                ii] = phase[jatom][ii] - (
                                                    MyCrystal.rprimd[ii][0] +
                                                    MyCrystal.rprimd[ii][1] +
                                                    MyCrystal.rprimd[ii][2])
                                            diffcoords[jatom][
                                                ii] = MyCrystal.atoms[
                                                    jatom].xcart[ii] + phase[
                                                        jatom][ii]
                                            jump = jump - (
                                                MyCrystal.rprimd[ii][0] +
                                                MyCrystal.rprimd[ii][1] +
                                                MyCrystal.rprimd[ii][2])
                                        elif jump < -MyCrystal.acell[ii] / 2:
                                            #print ('negatie jump',jump,jatom,MyCrystal.atoms[jatom].xcart[ii],oldpos[jatom].xcart[ii])
                                            phase[jatom][
                                                ii] = phase[jatom][ii] + (
                                                    MyCrystal.rprimd[ii][0] +
                                                    MyCrystal.rprimd[ii][1] +
                                                    MyCrystal.rprimd[ii][2])
                                            jump = jump + (
                                                MyCrystal.rprimd[ii][0] +
                                                MyCrystal.rprimd[ii][1] +
                                                MyCrystal.rprimd[ii][2])
                                            diffcoords[jatom][
                                                ii] = MyCrystal.atoms[
                                                    jatom].xcart[ii] + phase[
                                                        jatom][ii]
                                        else:
                                            diffcoords[jatom][
                                                ii] = MyCrystal.atoms[
                                                    jatom].xcart[ii] + phase[
                                                        jatom][ii]
                                        MyCrystal.atoms[jatom].vels[
                                            ii] = jump / TimeStep
                                        for jj in range(3):
                                            MyCrystal.atoms[jatom].xred[
                                                ii] = MyCrystal.atoms[jatom].xred[
                                                    ii] + MyCrystal.gprimd[ii][
                                                        jj] * MyCrystal.atoms[
                                                            jatom].xcart[ii]
                                            while MyCrystal.atoms[jatom].xred[
                                                    ii] >= 1.0:
                                                MyCrystal.atoms[jatom].xred[
                                                    ii] = MyCrystal.atoms[
                                                        jatom].xred[ii] - 1.0
                                (CurrentTime, TimeStep) = umd.print_snapshots(
                                    FileName, MyCrystal, TimeStep,
                                    (istep - InitialStep) * TimeStep,
                                    diffcoords)
                if (entry[0] == 'kin.'):  #reading the temperature
                    if len(entry) == 7:
                        MyCrystal.temperature = float(entry[5])
                    elif len(entry) == 6:
                        mixedtemp = entry[4]
                        MyCrystal.temperature = float(mixedtemp[-8:])
                    else:
                        print('defect on the temperature line', entry)
                if (flagrprimd > -1):  #reaeding the unit cell
                    #                    print 'entries are ',entry
                    MyCrystal.rprimd[flagrprimd][0] = float(
                        entry[0].split(',')[0])
                    MyCrystal.rprimd[flagrprimd][1] = float(
                        entry[1].split(',')[0])
                    MyCrystal.rprimd[flagrprimd][2] = float(
                        entry[2].split(')')[0])
                    MyCrystal.acell[flagrprimd] = math.sqrt(
                        MyCrystal.rprimd[flagrprimd][0] *
                        MyCrystal.rprimd[flagrprimd][0] +
                        MyCrystal.rprimd[flagrprimd][1] *
                        MyCrystal.rprimd[flagrprimd][1] +
                        MyCrystal.rprimd[flagrprimd][2] *
                        MyCrystal.rprimd[flagrprimd][2])
                    flagrprimd = flagrprimd + 1
                if (flagrprimd == 3):
                    MyCrystal.gprimd = MyCrystal.makegprimd()
                    #MyCrystal.cellvolume = MyCrystal.makevolume()
                    MyCrystal.density = MyCrystal.getdensity()
                    #print('gprimd  ',MyCrystal.gprimd)
                    #print(MyCrystal.cellvolume)
                    flagrprimd = -1
                if (entry[0] == 'direct'):
                    flagrprimd = flagrprimd + 1
                if (iatom > -1):  #reading the atomic positions
                    #print ('current iatom is ',iatom)
                    MyCrystal.atoms[iatom].xred = [0.0, 0.0, 0.0]
                    MyCrystal.atoms[iatom].vels = [0.0, 0.0, 0.0]
                    oldpos[iatom].xcart = MyCrystal.atoms[iatom].xcart
                    MyCrystal.atoms[iatom].xcart = [
                        float(entry[0]),
                        float(entry[1]),
                        float(entry[2])
                    ]
                    MyCrystal.atoms[iatom].forces = [
                        float(entry[3]),
                        float(entry[4]),
                        float(entry[5])
                    ]
                    iatom = iatom + 1
                    if (iatom == MyCrystal.natom):
                        iatom = -1
                if (entry[0] == 'POSITION'):
                    line = ff.readline()
                    iatom = 0
    return (CurrentTime, TimeStep)
예제 #13
0
def main(argv):
    UMDname = ''
    POPname = ''
    RADname = ''
    Nsteps = 5
    cubesize = 0.025
    ClusterMaxSize = 5
    AtomicRadius = 1.0
    Ballistic = 10.0
    umd.headerumd()
    try:
        opts, arg = getopt.getopt(
            argv, "hf:p:s:b:c:",
            ["fUMDfile", "pPOPfile", "sSTEP", "bBallistic", "cClusterMaxSize"])
    except getopt.GetoptError:
        print(
            'msd_cluster -f <UMD_filename> -p <POPuL_filename> -s <Nsteps> -b <Ballistic> -c <ClusterMaxSize>'
        )
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'Program to compute the mean square displacements for all the atomic species found by speciation.py. Usage:'
            )
            print(
                'msd_cluster -f <UMD_filename> -p <POPuL_filename> -s <Nsteps> -b <Ballistic> -c <ClusterMaxSize>'
            )
            print(
                'UMD_filename = input file with the trajectory, in UMD format.'
            )
            print(
                'POPuL_filename = input file with all the individual atomic clusters and their lifetimes in popul format.'
            )
            print(
                'Nsteps = frequency of sampling of the trajectory. Default = 1 (all steps are considered)'
            )
            print(
                'Ballistic = estimation of the ballistic part of the trajectory. Default is 0. Typical values of 100 are sufficient.'
            )
            print(
                'ClusterMaxSize = arbitrary upper size limit for defining checmnial species. Default = 5. You can safely assume values up to 10-12.'
            )
            sys.exit()
        elif opt in ("-f", "--fUMD_filename"):
            UMDname = str(arg)
            print('UMDname = ', UMDname)
        elif opt in ("-p", "--pPOP_filename"):
            POPname = str(arg)
            print('POPname = ', POPname)
        elif opt in ("-s", "--sNsteps"):
            Nsteps = int(arg)
            print('Density of sampling: every ', Nsteps, ' steps')
        elif opt in ("-s", "--bBallistic"):
            Ballistic = int(arg)
            print('Ballistic threshold: ', Ballistic, ' steps')
        elif opt in ("-c", "--cClusterMaxSize"):
            ClusterMaxSize = int(arg)
            print('Clusters smaller than ', ClusterMaxSize,
                  ' atoms are considered gas')

#checking the existence of the files before doing any other operation
    if os.path.isfile(UMDname):
        print('using ', UMDname, ' umd file')
    else:
        print('the UMD file ', UMDname, ' does not exist')
        sys.exit()

    if os.path.isfile(POPname):
        print('using ', POPname, ' population file')
    else:
        print('the UMD file ', POPname, ' does not exist')
        sys.exit()


#read the umd file and allocate structure
    MyCrystal = cr.Lattice()
    AllSnapshots = [cr.Lattice]
    (MyCrystal, AllSnapshots, TimeStep) = umd.read_absxcart(UMDname)

    ana_popul(MyCrystal, AllSnapshots, POPname, Ballistic, ClusterMaxSize,
              Nsteps)