Exemple #1
0
def NetCDFReader(source, frame=None, start=0, stop=None, step=1, format=None):

    opened = False
    if isinstance(source, str):
        opened = True
        source = netcdf_file(source)

    from quippy import Atoms

    DEG_TO_RAD = pi/180.0

    remap_names = {'coordinates': 'pos',
                   'velocities': 'velo',
                   'cell_lengths': None,
                   'cell_angles': None,
                   'cell_lattice': None,
                   'cell_rotated': None}

    prop_type_to_value = {PROPERTY_INT: 0,
                          PROPERTY_REAL: 0.0,
                          PROPERTY_STR: "",
                          PROPERTY_LOGICAL: False}

    prop_dim_to_ncols = {('frame','atom','spatial'): 3,
                         ('frame','atom','label'): 1,
                         ('frame', 'atom'): 1}

    if frame is not None:
        start = frame
        stop = frame+1
        step = 1
    else:
        if stop is None:
            stop = source.variables['cell_lengths'].shape[0]

    for frame in range(start, stop, step):
        cl = source.variables['cell_lengths'][frame]
        ca = source.variables['cell_angles'][frame]
        lattice = make_lattice(cl[0],cl[1],cl[2],ca[0]*DEG_TO_RAD,ca[1]*DEG_TO_RAD,ca[2]*DEG_TO_RAD)

        at = Atoms(n=netcdf_dimlen(source, 'atom'), lattice=lattice, properties={})

        for name, var in source.variables.iteritems():
            name = remap_names.get(name, name)

            if name is None:
                continue

            name = str(name) # in case it's a unicode string

            if 'frame' in var.dimensions:
                if 'atom' in var.dimensions:
                    # It's a property
                    value = var[frame]
                    if value.dtype.kind != 'S': value = value.T
                    at.add_property(name, value)
                else:
                    # It's a param
                    if var.dimensions == ('frame','string'):
                        # if it's a single string, join it and strip it
                        at.params[name] = ''.join(var[frame]).strip()
                    else:
                        if name == 'cutoff':
                            at.cutoff = var[frame]
                        elif name == 'cutoff_skin':
                            at.cutoff_skin = var[frame]
                        elif name == 'nneightol':
                            at.nneightol = var[frame]
                        elif name == 'pbc':
                            at.pbc = var[frame]
                        else:
                            at.params[name] = var[frame].T

        if 'cell_rotated' in source.variables:
            cell_rotated = source.variables['cell_rotated'][frame]
            orig_lattice = source.variables['cell_lattice'][frame]
            #if cell_rotated == 1:
            at.set_lattice(orig_lattice, True)

        yield at

    def close(self):
        if self.opened: source.close()
Exemple #2
0
structure_2d.set_cutoff(fs_potential.cutoff() + 2.0)
structure_2d.set_calculator(fs_potential)

minimiser = Minim(structure_2d, relax_positions=True, relax_cell=relax_cell)
minimiser.run()

castep_write(structure_2d, structure_2d.name, optimise=False, fix_lattice=True)

# From 10.1007/BF01184339, thermal expansion of tungsten is small, but for
# different temperatures we can expand a bit:
# 3000 K V/V0 = 1.11;
# 5000 K V/V0 = 1.29
#
if temperature == 1000:
    structure_2d.set_lattice(structure_2d.lattice * 1.003,
                             scale_positions=True)
elif temperature == 3000:
    structure_2d.set_lattice(structure_2d.lattice * (1.11**(1.0 / 3)),
                             scale_positions=True)
elif temperature == 5000:
    structure_2d.set_lattice(structure_2d.lattice * (1.29**(1.0 / 3)),
                             scale_positions=True)

molecular_dynamics(structure_2d,
                   fs_potential,
                   temperature,
                   total_steps=110000,
                   write_interval=2000,
                   equilibration_steps=10000)