Пример #1
0
def initialize_CM(n_images=8,
                  nest=1,
                  write_POSCAR=True,
                  write_python=True,
                  python_template='template.py'):
    """
    Initializes the NEB calculation.
    Parameters supported:
        n_images: Number of intermittent images in folders ## where # is a number. Default is 6.
        nest: Indicates how nested the trial is in the constrained minimization folder. Default is 1.
        write_POSCAR: If True, it will write a POSCAR file to the folders as POSCAR_start. Default is True.
        write_python: If True, it will copy the template file to the folders. Default is True.
    """

    file_base = relpath('.', '../' * nest).replace('/', '_')

    #Read initial and final state
    initial = read('./initial/CONTCAR')
    final = read('./final/CONTCAR')

    #Generating the interpolated images
    images = [initial]
    for i in range(n_images):
        images.append(initial.copy())
    images.append(final)
    interpolate(images)

    #for i in range(1, n_images+1):
    #    print 'Checking bond lengths for image %d' % i
    #    check_bond_lengths(images[i], False)

    compare_initial_final(initial, final)

    for i in range(0, n_images + 2):
        print(('Processing image %d' % i))
        folder = label_folder(i)
        if not exists(folder):
            makedirs(folder)
        if write_POSCAR:
            POSCAR_path = join(folder, 'POSCAR_start')
            print(('Writing image %d to %s' % (i, POSCAR_path)))
            write(POSCAR_path, images[i])
        if write_python:
            python_path = join(folder, '{}{}.py'.format(file_base, folder))
            print(('Copying template.py to %s' % python_path))
            sh.copyfile(python_template, python_path)
    print('Completed initialize_NEB')
Пример #2
0
def get_neb_trajectory(endpoint1, endpoint2=None, nimages=5):
    """Return a NEB trajectory with IDPP interpolation.

    Parameters
    ----------
    endpoint1 : Atoms object | list | str
        The second endpoint for use in the NEB. Can be either an
        atoms object, a path to an atoms object. Alternatively, it
        may be a list or 2 paths or atoms objects if endpoint2 is None.
    endpoint2 : Atoms object | str
        The second endpoint for use in the NEB. Can be either an
        atoms object or a path to an atoms object.
    nimages : int
        Number of images to include in the trajectory.

    Returns
    -------
    images : list of Atoms objects (N,)
        Trajectory of the provided endpoints.
    """
    if endpoint2 is None:
        trajectory = endpoint1
    else:
        trajectory = [endpoint1, endpoint2]

    for i, image in enumerate(trajectory):
        if isinstance(image, str):
            trajectory[i] = ase.io.read(image)

    images = [trajectory[0]]
    for i in range(nimages - 2):
        images += [trajectory[0].copy()]
    images += [trajectory[-1]]

    neb = ase.neb.NEB(images)
    neb.interpolate(method='idpp')

    return images
Пример #3
0
def test_interpolate_images_fixed(images, initial, average_pos):

    for image in images:
        image.set_constraint(FixAtoms([0]))

    # test raising a RuntimeError here
    with pytest.raises(RuntimeError, match=r"Constraint\(s\) in image number"):
        interpolate(images)

    interpolate(images, apply_constraint=True)
    assert images[1].positions == pytest.approx(images[0].positions)
    assert np.allclose(images[1].cell, initial.cell)

    interpolate(images, apply_constraint=False)
    assert images[1].positions == pytest.approx(average_pos)
    assert_interpolated([image.positions for image in images])
    assert np.allclose(images[1].cell, initial.cell)
Пример #4
0
NIMAGES = 9

print(("Restart = %r" % restart))
print(("NIMAGES = %d" % NIMAGES))

#Read initial and final state
initial = read('../In2O3_110_H_24/In2O3_110_H_24.traj')
final_path = '../In2O3_110_H_76/In2O3_110_H_76.traj'
final = read(final_path)

#Generating the interpolated images
images = [initial]
for i in range(NIMAGES):
    images.append(initial.copy())
images.append(final)
interpolate(images)

for i in range(0, (NIMAGES + 2)):
    print(('Processing image %d' % i))
    dir = label_folder(i)
    if not os.path.exists(dir):
        os.makedirs(dir)
    if restart:
        if i != 0 and i != (NIMAGES + 1):
            print("Restarting calculation. Copying CONTCAR to POSCAR")
            image = read(dir + '/CONTCAR')
        else:
            image = read(dir + '/POSCAR')
    else:
        print("Starting calculation. Writing POSCAR from interpolation")
        image = images[i]
Пример #5
0
def test_interpolate_images_cell_default_interpolate_cell_scaled_coord(
        images, initial):
    interpolate(images, interpolate_cell=True, use_scaled_coord=True)
    assert_interpolated([image.get_scaled_positions() for image in images])
    assert_interpolated([image.cell for image in images])
Пример #6
0
def test_interpolate_images_cell(images, initial, average_pos):
    interpolate(images, interpolate_cell=True)
    assert images[1].positions == pytest.approx(average_pos)
    assert_interpolated([image.positions for image in images])
    assert_interpolated([image.cell for image in images])
Пример #7
0
def test_interpolate_images_scaled_coord(images, initial):
    interpolate(images, use_scaled_coord=True)
    assert_interpolated([image.get_scaled_positions() for image in images])
    assert np.allclose(images[1].cell, initial.cell)
Пример #8
0
def test_interpolate_images_default(images, initial, average_pos):
    interpolate(images)
    assert images[1].positions == pytest.approx(average_pos)
    assert_interpolated([image.positions for image in images])
    assert np.allclose(images[1].cell, initial.cell)