Esempio n. 1
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
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)