예제 #1
0
import numpy as np
from ase.structure import bulk, estimate_lattice_constant
from ase.atoms import Atoms, string2symbols
from ase.data.molecules import molecule
from ase.visualize import view
from ase.io import read, write
from ase.constraints import FixAtoms

from gpaw.utilities import devnull
from gpaw.utilities.bulk2 import EMTRunner, GPAWRunner
from gpaw.parameters import InputParameters
from gpaw.mpi import world


defaults = InputParameters()

def build_parser():
    description = ('Run GPAW calculation for simple atoms, molecules or '
                   'bulk systems.')
    epilog = 'GPAW options: --%s.  ' % ', --'.join(defaults.keys())
    parser = optparse.OptionParser(usage='%prog [options] formula or filename',
                                   version='%prog 0.1',
                                   description=description + ' ' + epilog)

    struct = optparse.OptionGroup(parser, 'Structure')
    struct.add_option('-i', '--identifier',
                      help='String identifier added to filenames.')
    struct.add_option('-x', '--crystal-structure',
                      help='Crystal structure.',
                      choices=['sc', 'fcc', 'bcc', 'diamond', 'hcp', 
예제 #2
0
파일: ut_hsops.py 프로젝트: yihsuanliu/gpaw
# -------------------------------------------------------------------

from gpaw.test.ut_common import ase_svnversion, shapeopt, TestCase, \
    TextTestRunner, CustomTextTestRunner, defaultTestLoader, \
    initialTestLoader, create_random_atoms, create_parsize_maxbands

memstats = False
if memstats:
    # Developer use of this feature requires ASE 3.1.0 svn.rev. 905 or later.
    assert ase_svnversion >= 905  # wasn't bug-free untill 973!
    from ase.utils.memory import MemorySingleton, MemoryStatistics

# -------------------------------------------------------------------

p = InputParameters(spinpol=False)
xc = XC(p.xc)
p.setups = dict([(symbol, SetupData(symbol, xc.name)) for symbol in 'HO'])


class UTBandParallelSetup(TestCase):
    """
    Setup a simple band parallel calculation."""

    # Number of bands
    nbands = 36

    # Spin-paired, single kpoint
    nspins = 1
    nibzkpts = 1
예제 #3
0
def main(argv):
    defaults = InputParameters()
    parser = build_parser()
    populate_parser(parser, defaults)

    opts, args = parser.parse_args(argv)

    if opts.update is not None and opts.output is not None:
        parser.error('Cannot both update and write to new file.')

    if opts.update:
        if not os.path.isfile(opts.update):
            parser.error('No such file %s' % opts.update)
        outfilename = opts.update
        args = [outfilename] + args
    elif opts.output:
        outfilename = opts.output
    else:
        outfilename = None

    parameters = {}
    if opts.complete:
        parameters.update(defaults)

    for arg in args:
        loaded_parameters = load(arg)
        parameters.update(loaded_parameters)
        # We have to use the newly loaded info (target file)
        # to get new defaults!
        #
        # Rather ugly but hopefully it works
        # We can probably avoid this somehow, think about it in the future
        # (can one have different call formats like e.g. the 'du' man-page,
        # and somehow detect which one is relevant?)
        #parser2 = build_parser()
        #populate_parser(parser2, loaded_parameters)
        #opts, args2 = parser2.parse_args(argv)

    cli_args = vars(opts)
    cli_parameters = {}
    keys = defaults.keys()
    for key in defaults:
        obj = eval(cli_args[key])
        if defaults[key] != obj:
            cli_parameters[key] = obj
    parameters.update(cli_parameters)

    # Remove keys which are not changed from defaults
    if not opts.complete:
        # must call keys() since dict cannot change size during iteration
        for key in parameters.keys():
            if defaults[key] == parameters[key]:
                del parameters[key]

    if opts.pop:
        for kwarg in opts.pop.split(','):
            parameters.pop(kwarg)

    if outfilename is None:
        out = sys.stdout
    else:
        out = open(outfilename, 'w')
    print >> out, kwargs2str(**parameters)
예제 #4
0
# -------------------------------------------------------------------

from gpaw.test.ut_common import ase_svnversion, shapeopt, TestCase, \
    TextTestRunner, CustomTextTestRunner, defaultTestLoader, \
    initialTestLoader, create_random_atoms, create_parsize_maxbands

memstats = False
if memstats:
    # Developer use of this feature requires ASE 3.1.0 svn.rev. 905 or later.
    assert ase_svnversion >= 905 # wasn't bug-free untill 973!
    from ase.utils.memory import MemorySingleton, MemoryStatistics

# -------------------------------------------------------------------

p = InputParameters(spinpol=False)
xc = XC(p.xc)
p.setups = dict([(symbol, SetupData(symbol, xc.name)) for symbol in 'HN'])

class UTBandParallelSetup(TestCase):
    """
    Setup a simple band parallel calculation."""

    # Number of bands
    nbands = 36

    # Spin-paired, single kpoint
    nspins = 1
    nibzkpts = 1

    # Strided or blocked groups
예제 #5
0
    def __init__(self,
                 filename=None,
                 timer=None,
                 read_projections=True,
                 **kwargs):
        """ASE-calculator interface.

        The following parameters can be used: nbands, xc, kpts,
        spinpol, gpts, h, charge, symmetry, width, mixer,
        hund, lmax, fixdensity, convergence, txt, parallel,
        communicator, dtype, softgauss and stencils.

        If you don't specify any parameters, you will get:

        Defaults: neutrally charged, LDA, gamma-point calculation, a
        reasonable grid-spacing, zero Kelvin electronic temperature,
        and the number of bands will be equal to the number of atomic
        orbitals present in the setups. Only occupied bands are used
        in the convergence decision. The calculation will be
        spin-polarized if and only if one or more of the atoms have
        non-zero magnetic moments. Text output will be written to
        standard output.

        For a non-gamma point calculation, the electronic temperature
        will be 0.1 eV (energies are extrapolated to zero Kelvin) and
        all symmetries will be used to reduce the number of
        **k**-points."""

        PAWTextOutput.__init__(self)
        self.grid_descriptor_class = GridDescriptor
        self.input_parameters = InputParameters()

        if timer is None:
            self.timer = Timer()
        else:
            self.timer = timer

        self.scf = None
        self.forces = ForceCalculator(self.timer)
        self.stress_vv = None
        self.dipole_v = None
        self.magmom_av = None
        self.wfs = EmptyWaveFunctions()
        self.occupations = None
        self.density = None
        self.hamiltonian = None
        self.atoms = None
        self.iter = 0

        self.initialized = False
        self.nbands_parallelization_adjustment = None  # Somehow avoid this?

        # Possibly read GPAW keyword arguments from file:
        if filename is not None and filename.endswith('.gkw'):
            from gpaw.utilities.kwargs import load
            parameters = load(filename)
            parameters.update(kwargs)
            kwargs = parameters
            filename = None  # XXX

        if filename is not None:
            comm = kwargs.get('communicator', mpi.world)
            reader = gpaw.io.open(filename, 'r', comm)
            self.atoms = gpaw.io.read_atoms(reader)
            par = self.input_parameters
            par.read(reader)

        # _changed_keywords contains those keywords that have been
        # changed by set() since last time initialize() was called.
        self._changed_keywords = set()
        self.set(**kwargs)
        # Here in the beginning, effectively every keyword has been changed.
        self._changed_keywords.update(self.input_parameters)

        if filename is not None:
            # Setups are not saved in the file if the setups were not loaded
            # *from* files in the first place
            if par.setups is None:
                if par.idiotproof:
                    raise RuntimeError('Setups not specified in file. Use '
                                       'idiotproof=False to proceed anyway.')
                else:
                    par.setups = {None: 'paw'}
            if par.basis is None:
                if par.idiotproof:
                    raise RuntimeError('Basis not specified in file. Use '
                                       'idiotproof=False to proceed anyway.')
                else:
                    par.basis = {}

            self.initialize()
            self.read(reader, read_projections)
            if self.hamiltonian.xc.type == 'GLLB':
                self.occupations.calculate(self.wfs)

            self.print_cell_and_parameters()

        self.observers = []
예제 #6
0
파일: kwargs.py 프로젝트: eojons/gpaw-scme
def main(argv):
    defaults = InputParameters()
    parser = build_parser()
    populate_parser(parser, defaults)

    opts, args = parser.parse_args(argv)

    if opts.update is not None and opts.output is not None:
        parser.error('Cannot both update and write to new file.')
    
    if opts.update:
        if not os.path.isfile(opts.update):
            parser.error('No such file %s' % opts.update)
        outfilename = opts.update
        args = [outfilename] + args
    elif opts.output:
        outfilename = opts.output
    else:
        outfilename = None
    
    parameters = {}
    if opts.complete:
        parameters.update(defaults)
    
    for arg in args:
        loaded_parameters = load(arg)
        parameters.update(loaded_parameters)
        # We have to use the newly loaded info (target file)
        # to get new defaults!
        #
        # Rather ugly but hopefully it works
        # We can probably avoid this somehow, think about it in the future
        # (can one have different call formats like e.g. the 'du' man-page,
        # and somehow detect which one is relevant?)
        #parser2 = build_parser()
        #populate_parser(parser2, loaded_parameters)
        #opts, args2 = parser2.parse_args(argv)
    
    cli_args = vars(opts)
    cli_parameters = {}
    keys = defaults.keys()
    for key in defaults:
        obj = eval(cli_args[key])
        if defaults[key] != obj:
            cli_parameters[key] = obj
    parameters.update(cli_parameters)

    # Remove keys which are not changed from defaults
    if not opts.complete:
        # must call keys() since dict cannot change size during iteration
        for key in parameters.keys(): 
            if defaults[key] == parameters[key]:
                del parameters[key]

    if opts.pop:
        for kwarg in opts.pop.split(','):
            parameters.pop(kwarg)
    
    if outfilename is None:
        out = sys.stdout
    else:
        out = open(outfilename, 'w')
    print >> out, kwargs2str(**parameters)