Esempio n. 1
0
def Pd(tmpdir):
    from matdb.utility import relpath, copyonce
    from matdb.database import Controller
    from os import mkdir, symlink, remove, path

    target = relpath("./tests/Pd/matdb.yml")
    dbdir = str(tmpdir.join("pd_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    #We need to copy the POSCAR over from the testing directory to the temporary
    #one.
    from shutil import copy
    POSCAR = relpath("./tests/Pd/POSCAR")
    mkdir(path.join(dbdir, "seed"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd"))
    # the source file `matdb.yml` linked to might be gone, that left `matdb.yml` not an valid "file"
    # we need to get rid if it anyway
    try:
        remove("matdb.yml")
    except:
        pass
    symlink("{}.yml".format(target), "matdb.yml")

    result = Controller("matdb", dbdir)
    remove("matdb.yml")
    result = Controller(target, dbdir)
    return result
Esempio n. 2
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.

    cdb = Controller(args["dbspec"])

    matches = []
    configs = AtomsList()
    for pattern in args["p"]:
        for entry in cdb.find(pattern):
            for iatoms in entry.iconfigs:
                configs.append(iatoms)

    if args["format"] == "xyz":
        from matdb.conversion import to_xyz
        target = path.abspath(path.expanduser(args["o"]))
        to_xyz(configs, target, args["overwrite"])
Esempio n. 3
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    matplotlib.use('Agg')
    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    cdb = Controller(args["dbspec"])

    #We allow any number of databases to be plotted together at the same
    #tame. The `s` argument gives a `fnmatch` pattern for database paths.
    #For example `Pd.phonon-2.dynmatrix` specifies the dynamical matrix *step*
    #for suffix `2` of the phonon *database* of configuration `Pd`.
    dbs = []
    if args["d"]:
        for dbp in args["d"]:
            dbs.extend(cdb.find(dbp))

    pots = []
    if args["pots"]:
        for potp in args["pots"]:
            pots.extend(cdb.trainers.find(potp))

    if args["generic"]:

        objs = dbs + pots
        from matdb.plotting.plotter import PlotManager
        manager = PlotManager(cdb)
        for cname in args["generic"]:
            manager.plot(objs, cname)

    if args["bands"]:
        from matdb.plotting.comparative import band_plot
        band_plot(dbs, pots, **args)

    if args["generate"]:
        if len(pots) > 1:
            raise ValueError("Generate only operates for a single trainer "
                             "at a time; don't specify so many patterns.")
        pot = pots[0]
        _generate_pkl(pot, dbs, **args)

    if args["html"]:
        _generate_html(pots, **args)
def test_ran_seed(tmpdir):
    """Tests that the random seed gets set by the controller properly.
    """

    from matdb.utility import relpath
    from matdb.database import Controller

    target = relpath("./tests/general/ran_seed")
    dbdir = str(tmpdir.join("general"))
    mkdir(dbdir)
    cntrl = Controller(target, dbdir)

    splits = {"A": .5, "B": .75}
    root = str(tmpdir.join("legacy"))
    if not path.isdir(root):
        mkdir(root)
    folder = relpath("./tests/data/legacy")

    result = LegacyDatabase("AgPd-50",
                            root,
                            cntrl,
                            splits,
                            folder,
                            "p-50-*.xyz",
                            "ph",
                            energy="dft_energy",
                            force="dft_force",
                            virial="dft_virial")

    assert result.ran_seed == 100
Esempio n. 5
0
def AgCu(tmpdir):
    """Test the functionality of the substitution group for a small seed
    configuration where the number of possible random combinations is limited
    and repition is more likely.

    Attributes:
        atoms_seed(matdb.atoms.Atoms): The seed atoms objech configuration for db
            generation.
    """
    from matdb.utility import relpath
    from matdb.database import Controller
    from shutil import copy

    target = relpath("./tests/AgCu/matdb.yml")
    dbdir = str(tmpdir.join("agcu_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    # We need to copy the POSCAR from the testing directory to tempdir.
    POSCAR = relpath("./tests/AgCu/Ag1Cu5")
    mkdir(path.join(dbdir, "seed"))
    copy(POSCAR, path.join(dbdir, "seed", "Ag1Cu5"))
    if path.isfile("matdb.yml"):
        remove("matdb.yml")
    symlink("{}.yml".format(target), "matdb.yml")

    result = Controller(target, dbdir)
    return result
Esempio n. 6
0
def Act(tmpdir):

    target = relpath("./tests/AgPd/matdb.yml")
    dbdir = str(tmpdir.join("active_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    seed_root = path.join(dbdir, "seed")
    if not path.isdir(seed_root):
        mkdir(seed_root)

    for i in range(1, 4):
        cfg_target = path.join(seed_root, "Pd{0}".format(i))
        cfg_source = path.join(_get_reporoot(), "tests", "database", "files",
                               "Pd", "POSCAR{0}".format(i))
        copyonce(cfg_source, cfg_target)

    cntrl = Controller(target, dbdir)
    db = Database("active", dbdir, cntrl, [{"type": "active.Active"}], {}, 0)
    tcntrl = TController(db=db, root=dbdir, fits={})
    dbargs = {"root": dbdir, "parent": db, "calculator": tcntrl.db.calculator}
    result = Active(**dbargs)

    return result
Esempio n. 7
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    cdb = Controller(args["dbspec"])

    if args["t"]:
        matches = []
        for pattern in args["p"]:
            for entry in cdb.trainers.find(pattern):
                matches.append(entry)
        if len(matches) != 1:
            msg.err("Can only move a single trainer at a time."
                    "Found {} trainers.".format(len(matches)))
            exit(-1)

        _move_trainer(matches[0], **args)
Esempio n. 8
0
def Pd_no_seeds(tmpdir):
    target = relpath("./tests/Pd/matdb_no_seeds.yml")
    dbdir = str(tmpdir.join("manual_no_seeds_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))

    target = path.join(dbdir, "matdb")
    cntrl = Controller(target, dbdir)

    return cntrl
Esempio n. 9
0
def legDB(tmpdir):
    from matdb.utility import relpath, reporoot
    from matdb.database import Controller
    from os import mkdir

    target = relpath("./tests/legacy/matdb")
    dbdir = str(tmpdir.join("legacy"))
    mkdir(dbdir)

    return Controller(target, tmpdir=dbdir)
Esempio n. 10
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    import numpy as np
    from matdb import msg

    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    cdb = Controller(args["dbspec"])
    if args["xyz"]:
        cdb.split(cdb.trainers.split, recalc=args["recalc"])
    if args["t"]:
        cdb.trainers.jobfiles()
    if args["x"]:
        cdb.trainers.execute(args["tfilter"], args["sfilter"], args["dryrun"])
    if args["v"]:
        vdict = cdb.trainers.validate(args["data"], args["tfilter"],
                                      args["sfilter"], args["energy"],
                                      args["force"], args["virial"])
        if "e_ref" in vdict:
            e_err = np.std(vdict["e_ref"] - vdict["e_pot"])
            msg.info("Energy RMS: {0:.4f}".format(e_err))
        if "f_ref" in vdict:
            f_err = np.std(vdict["f_ref"].flatten() - vdict["f_pot"].flatten())
            msg.info("Force RMS: {0:.4f}".format(f_err))
        if "v_ref" in vdict:
            v_err = np.std(vdict["v_ref"].flatten() - vdict["v_pot"].flatten())
            msg.info("Virial RMS: {0:.4f}".format(v_err))

    if args["status"]:
        cdb.trainers.status()
Esempio n. 11
0
def Pd_db(tmpdir):
    from matdb.utility import relpath, reporoot
    from matdb.database import Controller
    from os import mkdir

    target = relpath("./tests/Pd/matdb")
    dbdir = str(tmpdir.join("pd_db"))
    mkdir(dbdir)

    #We need to copy the POSCAR over from the testing directory to the temporary
    #one.
    from shutil import copy
    POSCAR = relpath("./tests/Pd/POSCAR")
    copy(POSCAR, dbdir)

    Pd = Controller(target, dbdir)
    Pd.setup()

    #First, we need to copy the FORCE_SETS and total_dos.dat files so that we
    #don't have to recompile those (they are tested elsewhere).
    from matdb.utility import symlink
    troot = path.join(reporoot, "tests", "data", "Pd", "dynmatrix")
    files = ["FORCE_SETS", "total_dos.dat", "mesh.yaml"]
    for seq in Pd.find("Pd.phonon-*.dynmatrix"):
        for filename in files:
            target = path.join(seq.root, "phonopy", filename)
            source = path.join(troot,
                               "{0}__{1}".format(filename, seq.parent.name))
            symlink(target, source)

    Pd.cleanup()
    Pd.setup()

    files = ["OUTCAR", "output.xyz"]
    seq = Pd["Pd.modulate.modulations"]
    troot = path.join(reporoot, "tests", "data", "Pd", "modulations")
    for i in range(1, 6):
        key = "M.{0:d}".format(i)
        for filename in files:
            target = path.join(seq.root, key, filename)
            source = path.join(troot, "{0}__{1}".format(filename, key))
            symlink(target, source)

    return Pd
Esempio n. 12
0
def CoNiTi(tmpdir):
    from matdb.utility import relpath, copyonce
    from matdb.database import Controller
    from os import mkdir, symlink, remove

    target = relpath("./tests/files/CoNiTi.yml")
    dbdir = str(tmpdir.join("coniti_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    result = Controller(target, dbdir)
    return result
Esempio n. 13
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    cdb = Controller(args["dbspec"])

    matches = []
    for pattern in args["p"]:
        for entry in cdb.find(pattern):
            matches.append(entry)

    for db in matches:
        _fix_precomp(db)
Esempio n. 14
0
def mtpdb(tmpdir):
    from matdb.utility import relpath, reporoot, copyonce
    from matdb.database import Controller
    from os import mkdir, path

    target = relpath("./tests/mtp/CoWV.yml")
    dbdir = str(tmpdir.join("mlp_tests"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir,"matdb")

    cntrl = Controller(target, tmpdir=dbdir)

    return cntrl
Esempio n. 15
0
def Pd_copy(tmpdir):
    from matdb.utility import relpath, copyonce
    from matdb.database import Controller
    from os import path, remove, mkdir

    target = relpath("./tests/Pd/matdb_copy.yml")
    dbdir = str(tmpdir.join("pd_db_copy"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    from shutil import copy
    POSCAR = relpath("./tests/Pd/POSCAR")

    if path.isfile("matdb_copy.yml"):
        remove("matdb_copy.yml")

    result = Controller(target, dbdir)

    mkdir(path.join(dbdir, "seed"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd"))
    result = Controller(target, dbdir)
    return result
Esempio n. 16
0
def Act(tmpdir):

    target = relpath("./tests/AgPd/matdb.yml")
    dbdir = str(tmpdir.join("active_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir,"matdb")

    cntrl = Controller(target, dbdir)
    db = Database("active", dbdir, cntrl, [{"type":"active.Active"}], {}, 0)
    tcntrl = TController(db=db, root=dbdir, fits={})
    dbargs = {"root": dbdir, "parent": db,
              "calculator": tcntrl.db.calculator}
    result = Active(**dbargs)
    return result
Esempio n. 17
0
def Pd(tmpdir):
    target = relpath("./tests/Pd/matdb.yml")
    dbdir = str(tmpdir.join("manual_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))

    seed_root = path.join(dbdir, "seed")
    if not path.isdir(seed_root):
        mkdir(seed_root)

    for i in range(1, 4):
        cfg_target = path.join(seed_root, "Pd{0}".format(i))
        cfg_source = path.join(_get_reporoot(), "tests", "database", "files",
                               "Pd", "POSCAR{0}".format(i))
        copyonce(cfg_source, cfg_target)

    target = path.join(dbdir, "matdb")
    cntrl = Controller(target, dbdir)

    return cntrl
Esempio n. 18
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """
    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print(
        "This is free software, and you are welcome to redistribute it under "
        "certain conditions.")
    if args is None:
        return

    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    cdb = Controller(args["dbspec"])

    if args["d"]:
        _generic_find(cdb, "Database Context Instances", args["p"])
    if args["t"]:
        _generic_find(cdb.trainers, "Fitter Context Instances", args["p"])
Esempio n. 19
0
def Pd_split(tmpdir):
    from matdb.utility import relpath, copyonce
    from matdb.database import Controller
    from os import mkdir, path

    target = relpath("./tests/Pd/matdb_split.yml")
    dbdir = str(tmpdir.join("pd_db_splits"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))
    target = path.join(dbdir, "matdb")

    from shutil import copy
    POSCAR = relpath("./tests/Pd/POSCAR")
    mkdir(path.join(dbdir, "seed"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd-1"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd-2"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd-3"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd-4"))
    copy(POSCAR, path.join(dbdir, "seed", "Pd-5"))

    result = Controller(target, dbdir)
    return result
Esempio n. 20
0
def Pd_not_extractable(tmpdir):
    target = relpath("./tests/Pd/matdb_not_extractable.yml")
    dbdir = str(tmpdir.join("manual_not_extractale_db"))
    mkdir(dbdir)
    copyonce(target, path.join(dbdir, "matdb.yml"))

    seed_root = path.join(dbdir, "seed")
    if not path.isdir(seed_root):
        mkdir(seed_root)

    cfg_target = path.join(seed_root, "Pd")
    cfg_source = path.join(_get_reporoot(), "tests", "database", "files", "Pd",
                           "POSCAR1")
    copyonce(cfg_source, cfg_target)

    target = path.join(dbdir, "matdb")
    cntrl = Controller(target, dbdir)

    # these 3 lines are just added to cover dbargs["calculator"] not None in __init__
    db = Database("phonon", dbdir, cntrl, [{"type": "simple.Manual"}], {}, 0)
    dbargs = {"root": dbdir, "parent": db, "calculator": cntrl.calculator}
    mdb = Manual(extractable=False, **dbargs)

    return cntrl
Esempio n. 21
0
def run(args):
    """Runs the matdb setup and cleanup to produce database files.
    """

    print("matdb  Copyright (C) 2019  HALL LABS")
    print("This program comes with ABSOLUTELY NO WARRANTY.")
    print("This is free software, and you are welcome to redistribute it under "
          "certain conditions.")

    if args is None:
        return
    #No matter what other options the user has chosen, we will have to create a
    #database controller for the specification they have given us.
    from matdb.database import Controller
    """The Controller class is to help the rest of the software parse and store configuration settings from the YAML file. 
    """
    cdb = Controller(args["dbspec"])
    if args["s"]:
        cdb.setup(args["rerun"], args["dfilter"])
    if args["x"]:
        cdb.execute(args["recover"], args["dfilter"], dryrun=args["dryrun"])
    if args["e"]:
        cdb.extract(args["dfilter"], cleanup=args["clean"], asis=args["asis"])

    if args["recover"] and not args["x"]:
        cdb.recover(args["rerun"], args["dfilter"])
        
    if args["status"]:
        cdb.status(args["busy"], args["dfilter"])