Пример #1
0
 def test_from_file_3(self):
     """
     Test (pychemia.core.from_file)                              :
     """
     filename = 'tests/data/abinit_05/structure.json'
     st = pychemia.structure_from_file(filename)
     self.assertEqual(st.nsites, 20)
Пример #2
0
 def test_from_file_1(self):
     """
     Test (pychemia.core.from_file)                              :
     """
     filename = 'tests/data/vasp_07/POSCAR_new'
     st = pychemia.structure_from_file(filename)
     self.assertEqual(st.nsites, 44)
Пример #3
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv[1:], "hs:o:n:b:e:t:", ["help", "structure=", "output=", "nparal=",
                                                               "binary=", "energy_tol=", "target_forces="])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(2)

    if len(opts) == 0:
        usage(argv[0])
        sys.exit(2)

    # Default Values
    workdir = '.'
    structure_file = 'POSCAR'
    output_file = 'pcm_results.json'
    nparal = 2
    energy_tol = 1E-3
    target_forces = 1E-3
    binary = 'vasp'

    for opt, arg in opts:

        if opt in ("-h", "--help"):
            usage(argv[0])
            sys.exit()
        elif opt in ("-s", "--structure"):
            structure_file = arg
        elif opt in ("-o", "--output"):
            output_file = arg
        elif opt in ("-n", "--nparal"):
            nparal = get_int(arg)
        elif opt in ("-b", "--binary"):
            binary = arg
        elif opt in ("-e", "--energy_tol"):
            energy_tol = get_float(arg)
        elif opt in ("-t", "--target_forces"):
            target_forces = get_float(arg)
        elif opt in ("-s", "--structure"):
            structure_file = arg

    structure = pychemia.structure_from_file(structure_file)
    if structure is None:
        print(" ERROR: Invalid structure, no structure could be obtained from '%s'" % structure_file)
        sys.exit(2)

    if structure_file == 'POSCAR':
        os.rename('POSCAR', 'POSCAR_original')

    print("\n PyChemia VASP Relaxator")
    print(" =======================\n")
    print(" VASP binary         : ", binary)
    print(" Energy tolerance    : ", energy_tol)
    print(" Target forces       : ", target_forces)
    print(" MPI number of procs : ", nparal)
    print(" Structure           :\n")
    print(structure)

    wf = open(output_file, 'w')
    data = {'input': {'binary': binary,
                      'energy_tol': energy_tol,
                      'target_forces': target_forces,
                      'nparal': nparal,
                      'structure': structure.to_dict}}
    json.dump(data, wf)
    wf.close()

    # First Round (Relaxing the original structure)
    print('\nFirst Round')
    print('===========')

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(structure, energy_tolerance=energy_tol)
    if os.path.isfile('convergence_encut.json'):
        print('A previous convergence study was found, loading...')
        ce.load()
    if not ce.is_converge:
        ce.run(nparal)
        ce.save()
        ce.plot()
    encut = ce.best_encut

    data['output'] = {'1R_ENCUT': encut}
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(structure, encut=encut, energy_tolerance=energy_tol)
    if os.path.isfile('convergence_kpoints.json'):
        print('A previous convergence study was found, loading...')
        ce.load()
    if not ce.is_converge:
        ce.run(nparal)
        ce.save()
        ce.plot()
    kp = ck.best_kpoints

    data['output'] = {'1R_KPOINTS': list(kp.grid)}
    print(data)
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    os.rename('convergence_encut.json', 'convergence_encut_phase1.json')
    os.rename('convergence_encut.pdf', 'convergence_encut_phase1.pdf')
    os.rename('convergence_kpoints.json', 'convergence_kpoints_phase1.json')
    os.rename('convergence_kpoints.pdf', 'convergence_kpoints_phase1.pdf')

    cleaner()
    print('\nIonic Relaxation')
    print('----------------\n')
    vr = IonRelaxation(structure=structure, encut=encut, kp_grid=kp.grid, workdir=workdir,
                       target_forces=10 * target_forces)
    vr.run(nparal)

    structure = vr.get_final_geometry()
    structure.save_json(workdir + os.sep + 'structure_phase1.json')

    data['output'] = {'1R_structure': structure.to_dict}
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    # Second Round (Symetrize structure and redo convergences)
    st = symmetrize(structure)

    print('\nSecond Round')
    print('============')

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(st, encut=encut, energy_tolerance=energy_tol, recover=True)
    ck.run(nparal)
    ck.save()
    ck.plot()
    kp = ck.best_kpoints

    data['output'] = {'2R_KPOINTS': list(kp.grid)}
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(st, energy_tolerance=energy_tol, kpoints=kp)
    ce.run(nparal)
    ce.save()
    ce.plot()
    encut = ce.best_encut

    data['output'] = {'2R_ENCUT': encut}
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    os.rename('convergence_encut.json', 'convergence_encut_phase2.json')
    os.rename('convergence_encut.pdf', 'convergence_encut_phase2.pdf')
    os.rename('convergence_kpoints.json', 'convergence_kpoints_phase2.json')
    os.rename('convergence_kpoints.pdf', 'convergence_kpoints_phase2.pdf')

    cleaner()
    print('\nIonic Relaxation')
    print('----------------\n')
    vr = IonRelaxation(structure=st, workdir='.', encut=encut, kp_grid=kp.grid, target_forces=target_forces)
    vr.run(nparal)

    structure = vr.get_final_geometry()
    structure.save_json(workdir + os.sep + 'structure_phase2.json')

    data['output'] = {'2R_structure': structure.to_dict}

    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
def main(argv):
    try:
        opts, args = getopt.getopt(argv[1:], "hs:o:i:f:d:n:b:e:x:t:", ["help", "structure=", "output=", "ini_factor=",
                                                                       "fin_factor=", "delta_factor", "nparal=",
                                                                       "binary=", "energy_tol=", "expansion=",
                                                                       "target_forces"])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(2)

    if len(opts) == 0:
        usage(argv[0])
        sys.exit(2)

    # Default Values
    structure_file = 'POSCAR'
    delta_factor = 0.01
    ini_factor = 0.01
    fin_factor = 0.1
    output_file = 'IdealStrength.json'
    nparal = 2
    energy_tol = 1E-3
    target_forces = 1E-3
    binary = 'vasp'
    expansion = 111

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage(argv[0])
            sys.exit()
        elif opt in ("-s", "--structure"):
            structure_file = arg
        elif opt in ("-o", "--output"):
            output_file = arg
        elif opt in ("-i", "--ini_factor"):
            ini_factor = get_float(arg)
        elif opt in ("-f", "--fin_factor"):
            fin_factor = get_float(arg)
        elif opt in ("-d", "--delta_factor"):
            delta_factor = get_float(arg)
        elif opt in ("-n", "--nparal"):
            nparal = get_int(arg)
        elif opt in ("-b", "--binary"):
            binary = arg
        elif opt in ("-e", "--energy_tol"):
            energy_tol = get_float(arg)
        elif opt in ("-t", "--target_forces"):
            target_forces = get_float(arg)
        elif opt in ("-x", "--expansion"):
            expansion = get_int(arg)
        elif opt in ("-s", "--structure"):
            structure_file = get_int(arg)

    expansion = [int(expansion / 100), int(expansion / 10) % 10, expansion % 10]
    if len(expansion) == 0:
        print(" ERROR: ini_factor, fin_factor and delta_factor are not creating a finite range of values")
        sys.exit(2)

    structure = pychemia.structure_from_file(structure_file)
    if structure is None:
        print(" ERROR: Invalid structure, no structure could be obtained from '%s'" % structure_file)
        sys.exit(2)

    if structure_file == 'POSCAR':
        os.rename('POSCAR', 'POSCAR_original')

    print("\n PyChemia Ideal Strenght")
    print(" =======================\n")
    print(" Scaling factors     : ", str(np.arange(ini_factor, fin_factor + 0.9 * delta_factor, delta_factor)))
    print(" Executable          : ", binary)
    print(" Energy tolerance    : ", energy_tol)
    print(" Target forces       : ", target_forces)
    print(" Expansion directions: ", str(expansion))
    print(" MPI number of procs : ", nparal)
    print(" Structure           :\n")
    print(structure)

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(structure, energy_tolerance=energy_tol, binary=binary)
    if os.path.isfile('convergence_encut.json'):
        print('A previous convergence study was found, loading...')
        ce.load()
    if not ce.is_converge:
        ce.run(nparal)
        ce.save()
        ce.plot()
    encut = ce.best_encut
    print('ENCUT: ', encut)

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(structure, workdir='.', binary=binary, encut=encut,
                               energy_tolerance=energy_tol, recover=True)
    if os.path.isfile('convergence_kpoints.json'):
        print('A previous convergence study was found, loading...')
        ck.load()
    if not ck.is_converge:
        ck.run(nparal)
        ck.save()
        ck.plot()
    kp = ck.best_kpoints
    kp_density = kp.get_density_of_kpoints(structure.lattice)
    print('KPOINT GRID', kp.grid)

    strenght = IdealStrength(structure, ini_factor, fin_factor, delta_factor, kp, kp_density, expansion, encut,
                             nparal, binary, target_forces, output_file)

    strenght.run(nparal)
    strenght.save()

    cleaner()
Пример #5
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv[1:], "hs:o:n:b:e:", ["help", "structure=", "output=", "nparal=",
                                                             "binary=", "energy_tol="])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(2)

    if len(opts) == 0:
        usage(argv[0])
        sys.exit(2)

    # Default Values
    structure_file = 'POSCAR'
    output_file = 'static_calculation.json'
    nparal = 2
    energy_tol = 1E-3
    binary = 'vasp'

    for opt, arg in opts:

        if opt in ("-h", "--help"):
            usage(argv[0])
            sys.exit()
        elif opt in ("-s", "--structure"):
            structure_file = arg
        elif opt in ("-o", "--output"):
            output_file = arg
        elif opt in ("-n", "--nparal"):
            nparal = get_int(arg)
        elif opt in ("-b", "--binary"):
            binary = arg
        elif opt in ("-e", "--energy_tol"):
            energy_tol = get_float(arg)
        elif opt in ("-s", "--structure"):
            structure_file = get_int(arg)

    structure = pychemia.structure_from_file(structure_file)
    if structure is None:
        print(" ERROR: Invalid structure, no structure could be obtained from '%s'" % structure_file)
        sys.exit(2)

    if structure_file == 'POSCAR':
        os.rename('POSCAR', 'POSCAR_original')

    print("\n PyChemia VASP Static")
    print(" =======================\n")
    print(" Executable          : ", binary)
    print(" Energy tolerance    : ", energy_tol)
    print(" MPI number of procs : ", nparal)
    print(" Structure           :\n")
    print(structure)
    data = {}

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(structure, energy_tolerance=energy_tol, binary=binary)
    ce.run(nparal)
    ce.save()
    ce.plot()
    encut = ce.best_encut

    cvg = json.load(open('task.json'))
    data['Convergece Cut-off'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(structure, encut=encut, energy_tolerance=energy_tol, binary=binary)
    ck.run(nparal)
    ck.save()
    ck.plot()
    kp = ck.best_kpoints

    cvg = json.load(open('task.json'))
    data['Convergece KPoints'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()

    job = StaticCalculation(structure, encut=encut, kpoints=kp, binary=binary)
    job.run(nparal)
    job.save()
    cvg = json.load(open('task.json'))
    data['Static'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
Пример #6
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv[1:], "hs:o:n:b:e:", [
            "help", "structure=", "output=", "nparal=", "binary=",
            "energy_tol="
        ])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(2)

    if len(opts) == 0:
        usage(argv[0])
        sys.exit(2)

    # Default Values
    structure_file = 'POSCAR'
    output_file = 'static_calculation.json'
    nparal = 2
    energy_tol = 1E-3
    binary = 'vasp'

    for opt, arg in opts:

        if opt in ("-h", "--help"):
            usage(argv[0])
            sys.exit()
        elif opt in ("-s", "--structure"):
            structure_file = arg
        elif opt in ("-o", "--output"):
            output_file = arg
        elif opt in ("-n", "--nparal"):
            nparal = get_int(arg)
        elif opt in ("-b", "--binary"):
            binary = arg
        elif opt in ("-e", "--energy_tol"):
            energy_tol = get_float(arg)
        elif opt in ("-s", "--structure"):
            structure_file = get_int(arg)

    structure = pychemia.structure_from_file(structure_file)
    if structure is None:
        print(
            " ERROR: Invalid structure, no structure could be obtained from '%s'"
            % structure_file)
        sys.exit(2)

    if structure_file == 'POSCAR':
        os.rename('POSCAR', 'POSCAR_original')

    print("\n PyChemia VASP Static")
    print(" =======================\n")
    print(" Executable          : ", binary)
    print(" Energy tolerance    : ", energy_tol)
    print(" MPI number of procs : ", nparal)
    print(" Structure           :\n")
    print(structure)
    data = {}

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(structure,
                                 energy_tolerance=energy_tol,
                                 binary=binary)
    ce.run(nparal)
    ce.save()
    ce.plot()
    encut = ce.best_encut

    cvg = json.load(open('task.json'))
    data['Convergece Cut-off'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(structure,
                               encut=encut,
                               energy_tolerance=energy_tol,
                               binary=binary)
    ck.run(nparal)
    ck.save()
    ck.plot()
    kp = ck.best_kpoints

    cvg = json.load(open('task.json'))
    data['Convergece KPoints'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()

    job = StaticCalculation(structure, encut=encut, kpoints=kp, binary=binary)
    job.run(nparal)
    job.save()
    cvg = json.load(open('task.json'))
    data['Static'] = cvg
    wf = open(output_file, 'w')
    json.dump(data, wf)
    wf.close()

    cleaner()
Пример #7
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv[1:], "hs:o:i:f:d:n:b:e:x:t:", [
            "help", "structure=", "output=", "ini_factor=", "fin_factor=",
            "delta_factor", "nparal=", "binary=", "energy_tol=", "expansion=",
            "target_forces"
        ])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(2)

    if len(opts) == 0:
        usage(argv[0])
        sys.exit(2)

    # Default Values
    structure_file = 'POSCAR'
    delta_factor = 0.01
    ini_factor = 0.01
    fin_factor = 0.1
    output_file = 'IdealStrength.json'
    nparal = 2
    energy_tol = 1E-3
    target_forces = 1E-3
    binary = 'vasp'
    expansion = 111

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage(argv[0])
            sys.exit()
        elif opt in ("-s", "--structure"):
            structure_file = arg
        elif opt in ("-o", "--output"):
            output_file = arg
        elif opt in ("-i", "--ini_factor"):
            ini_factor = get_float(arg)
        elif opt in ("-f", "--fin_factor"):
            fin_factor = get_float(arg)
        elif opt in ("-d", "--delta_factor"):
            delta_factor = get_float(arg)
        elif opt in ("-n", "--nparal"):
            nparal = get_int(arg)
        elif opt in ("-b", "--binary"):
            binary = arg
        elif opt in ("-e", "--energy_tol"):
            energy_tol = get_float(arg)
        elif opt in ("-t", "--target_forces"):
            target_forces = get_float(arg)
        elif opt in ("-x", "--expansion"):
            expansion = get_int(arg)
        elif opt in ("-s", "--structure"):
            structure_file = get_int(arg)

    expansion = [
        int(expansion / 100),
        int(expansion / 10) % 10, expansion % 10
    ]
    if len(expansion) == 0:
        print(
            " ERROR: ini_factor, fin_factor and delta_factor are not creating a finite range of values"
        )
        sys.exit(2)

    structure = pychemia.structure_from_file(structure_file)
    if structure is None:
        print(
            " ERROR: Invalid structure, no structure could be obtained from '%s'"
            % structure_file)
        sys.exit(2)

    if structure_file == 'POSCAR':
        os.rename('POSCAR', 'POSCAR_original')

    print("\n PyChemia Ideal Strenght")
    print(" =======================\n")
    print(
        " Scaling factors     : ",
        str(
            np.arange(ini_factor, fin_factor + 0.9 * delta_factor,
                      delta_factor)))
    print(" Executable          : ", binary)
    print(" Energy tolerance    : ", energy_tol)
    print(" Target forces       : ", target_forces)
    print(" Expansion directions: ", str(expansion))
    print(" MPI number of procs : ", nparal)
    print(" Structure           :\n")
    print(structure)

    cleaner()
    print('\nConvergence of Cut-off Energy')
    print('-----------------------------\n')
    ce = ConvergenceCutOffEnergy(structure,
                                 energy_tolerance=energy_tol,
                                 binary=binary)
    if os.path.isfile('convergence_encut.json'):
        print('A previous convergence study was found, loading...')
        ce.load()
    if not ce.is_converge:
        ce.run(nparal)
        ce.save()
        ce.plot()
    encut = ce.best_encut
    print('ENCUT: ', encut)

    cleaner()
    print('\nConvergence of K-Point Grid')
    print('---------------------------\n')
    ck = ConvergenceKPointGrid(structure,
                               workdir='.',
                               binary=binary,
                               encut=encut,
                               energy_tolerance=energy_tol,
                               recover=True)
    if os.path.isfile('convergence_kpoints.json'):
        print('A previous convergence study was found, loading...')
        ck.load()
    if not ck.is_converge:
        ck.run(nparal)
        ck.save()
        ck.plot()
    kp = ck.best_kpoints
    kp_density = kp.get_density_of_kpoints(structure.lattice)
    print('KPOINT GRID', kp.grid)

    strenght = IdealStrength(structure, ini_factor, fin_factor, delta_factor,
                             kp, kp_density, expansion, encut, nparal, binary,
                             target_forces, output_file)

    strenght.run(nparal)
    strenght.save()

    cleaner()