Example #1
0
def test_pseudopotential_group_get_structure():
    """Test get_pseudos from structure"""
    Pseudo = DataFactory("gaussian.pseudo")
    PseudopotentialGroup = GroupFactory("gaussian.pseudo")

    pseudogroup, created = PseudopotentialGroup.objects.get_or_create("test")
    assert created
    pseudogroup.store()

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    pseudogroup.add_nodes([pseudo.store() for pseudo in pseudos])

    StructureData = DataFactory("structure")
    structure = StructureData(cell=[[4.796302, 0, 0], [0, 4.796302, 0],
                                    [0, 0, 4.796302]],
                              pbc=True)
    structure.append_atom(position=(0.000, 0.000, 0.000), symbols="Li")
    structure.append_atom(position=(0.500, 0.500, 0.000), symbols="Li")
    structure.append_atom(position=(0.500, 0.000, 0.500), symbols="Li")
    structure.append_atom(position=(0.000, 0.500, 0.500), symbols="Li")
    structure.append_atom(position=(0.000, 0.500, 0.000), symbols="H")
    structure.append_atom(position=(0.000, 0.000, 0.500), symbols="H")
    structure.append_atom(position=(0.500, 0.000, 0.000), symbols="H")
    structure.append_atom(position=(0.500, 0.500, 0.500), symbols="H")

    retrieved_pseudos = pseudogroup.get_pseudos(structure=structure)

    assert retrieved_pseudos == {
        "Li": [p for p in pseudos if p.element == "Li"],
        "H": [p for p in pseudos if p.element == "H"],
    }
Example #2
0
def test_get_matching_empty():
    Pseudo = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    with pytest.raises(NotExistent):
        pseudos[0].get_matching_basisset()
Example #3
0
def test_n_orbital_functions():
    BasisSet = DataFactory("gaussian.basisset")

    with open(TEST_DIR.joinpath("BASIS_MOLOPT.Hf"), "r") as fhandle:
        bsets = BasisSet.from_cp2k(fhandle)

    assert bsets
    assert bsets[0].n_orbital_functions == 1 * 3 + 3 * 2 + 5 * 2 + 7 * 1  # l=0,1,2,3 with respective nshells=3,2,2,1
Example #4
0
def test_get_matching_empty():
    BasisSet = DataFactory("gaussian.basisset")

    with open(TEST_DIR.joinpath("BASIS_MOLOPT.H"), "r") as fhandle:
        bsets = BasisSet.from_cp2k(fhandle)

    with pytest.raises(NotExistent):
        bsets[0].get_matching_pseudopotential()
Example #5
0
def test_lookup():
    BasisSet = DataFactory("gaussian.basisset")

    with open(TEST_DIR.joinpath("BASIS_MOLOPT.H"), "r") as fhandle:
        bsets = BasisSet.from_cp2k(fhandle)
        bsets[0].store()

    basis_H = BasisSet.get(element="H", name="SZV-MOLOPT-GTH")
    assert basis_H
Example #6
0
def test_nlcc_import():
    """With the usage of the cp2k-input-tools for file handling we also gained support for the NLCC pseudos"""
    Pseudopotential = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("NLCC_POTENTIALS"), "r") as fhandle:
        # get only the He PADE pseudo
        pseudos = Pseudopotential.from_cp2k(
            fhandle, filters={"element": lambda x: x == "C"})

    assert len(pseudos) == 1
Example #7
0
def test_import_from_cp2k():
    BasisSet = DataFactory("gaussian.basisset")

    with open(TEST_DIR.joinpath("BASIS_MOLOPT.H"), "r") as fhandle:
        bsets = BasisSet.from_cp2k(fhandle)

    assert len(bsets) == 1

    bsets[0].store()

    # check that the name is used for the node label
    assert bsets[0].label == bsets[0].name
Example #8
0
def test_to_cp2k():
    """Check whether writing a CP2K datafile works"""
    Pseudo = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    fhandle = io.StringIO()
    for pseudo in pseudos:
        pseudo.to_cp2k(fhandle)

    assert fhandle.getvalue()
Example #9
0
def test_to_cp2k_nlcc_missing():
    """Check whether writing a CP2K datafile works, also with missing NLCC attribute"""
    Pseudo = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    fhandle = io.StringIO()
    for pseudo in pseudos:
        del pseudo.attributes["nlcc"]
        pseudo.to_cp2k(fhandle)

    assert fhandle.getvalue()
Example #10
0
def cp2k_basissets(bsdataset):
    """Returns basisset objects from the data above"""
    fhandle = StringIO(BSET_DATA[bsdataset])
    BasisSet = DataFactory("gaussian.basisset")  # pylint: disable=invalid-name
    bsets = {}
    for bset in BasisSet.from_cp2k(fhandle):
        bset.store(
        )  # store because the validator accesses it when raising an error

        if bset.element in bsets:
            # if we have multiple basissets per element, pass them as a list
            if not isinstance(bsets[bset.element], list):
                bsets[bset.element] = [bsets[bset.element]]
            bsets[bset.element] += [bset]
        else:
            bsets[bset.element] = bset
    return bsets
Example #11
0
def test_lookup():
    Pseudopotential = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS"), "r") as fhandle:
        # get only the He PBE pseudo
        pseudos = Pseudopotential.from_cp2k(fhandle,
                                            filters={
                                                "element":
                                                lambda x: x == "He",
                                                "tags":
                                                lambda x: set(
                                                    ("PBE", )).issubset(x)
                                            })
        pseudos[0].store()

    assert Pseudopotential.get(element="He", name="GTH-PBE-q2")
    assert Pseudopotential.get(element="He", name="GTH-PBE")
Example #12
0
def test_pseudopotential_group_get():
    Pseudo = DataFactory("gaussian.pseudo")
    PseudopotentialGroup = GroupFactory("gaussian.pseudo")

    pseudogroup, created = PseudopotentialGroup.objects.get_or_create("test")
    assert created
    pseudogroup.store()

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    pseudogroup.add_nodes([pseudo.store() for pseudo in pseudos])

    retrieved_pseudos = pseudogroup.get_pseudos(elements=["Li", "H"])

    assert retrieved_pseudos == {
        "Li": [p for p in pseudos if p.element == "Li"],
        "H": [p for p in pseudos if p.element == "H"],
    }
Example #13
0
def test_import_from_cp2k():
    Pseudopotential = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS"), "r") as fhandle:
        # get only the He PADE pseudo
        pseudos = Pseudopotential.from_cp2k(fhandle,
                                            filters={
                                                "element":
                                                lambda x: x == "He",
                                                "tags":
                                                lambda x: set(
                                                    ("PADE", )).issubset(x)
                                            })

    assert len(pseudos) == 1

    pseudos[0].store()

    # check that the name is used for the node label
    assert pseudos[0].label == pseudos[0].name
Example #14
0
def test_get():
    from aiida.common.exceptions import MultipleObjectsError, NotExistent

    BasisSet = DataFactory("gaussian.basisset")

    with open(TEST_DIR.joinpath("MOLOPT_PBE.LiH"), "r") as fhandle:
        bsets = BasisSet.from_cp2k(fhandle)

    for bset in bsets:
        bset.store()

    # getting a single one should work
    bset = BasisSet.get(element="H", name="DZVP-MOLOPT-PBE-GTH-q1")
    assert bset.element == "H" and bset.name == "DZVP-MOLOPT-PBE-GTH-q1"

    with pytest.raises(NotExistent):
        BasisSet.get(element="C")

    # leaving away the name should return multiple ones, raising an error
    with pytest.raises(MultipleObjectsError):
        BasisSet.get(element="H")
Example #15
0
def test_get():
    from aiida.common.exceptions import MultipleObjectsError, NotExistent

    Pseudo = DataFactory("gaussian.pseudo")

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    for pseudo in pseudos:
        pseudo.store()

    # getting a single one should work
    pseudo = Pseudo.get(element="H", name="GTH-PBE-q1")
    assert pseudo.element == "H" and pseudo.name == "GTH-PBE-q1"

    with pytest.raises(NotExistent):
        Pseudo.get(element="C")

    # leaving away the name should return multiple ones, raising an error
    with pytest.raises(MultipleObjectsError):
        Pseudo.get(element="Li")
Example #16
0
def load_data(prefix="MY-"):
    """
    This is something the user will usually do only ONCE and most likely by
    using the CLI of the aiida-gaussian-datatypes.
    """

    # Note: the basissets and pseudos deliberately have a prefix to avoid matching
    #       any CP2K provided entries which may creep in via the DATA_DIR

    bset_input = f"""\
     H  {prefix}AUTO-DZVP-MOLOPT-GTH {prefix}AUTO-DZVP-MOLOPT-GTH-q1
     1
     2 0 1 7 2 1
         11.478000339908  0.024916243200 -0.012512421400  0.024510918200
          3.700758562763  0.079825490000 -0.056449071100  0.058140794100
          1.446884268432  0.128862675300  0.011242684700  0.444709498500
          0.716814589696  0.379448894600 -0.418587548300  0.646207973100
          0.247918564176  0.324552432600  0.590363216700  0.803385018200
          0.066918004004  0.037148121400  0.438703133000  0.892971208700
          0.021708243634 -0.001125195500 -0.059693171300  0.120101316500

     O  {prefix}AUTO-DZVP-MOLOPT-SR-GTH {prefix}AUTO-DZVP-MOLOPT-SR-GTH-q6
     1
     2 0 2 5 2 2 1
         10.389228018317  0.126240722900  0.069215797900 -0.061302037200 -0.026862701100  0.029845227500
          3.849621072005  0.139933704300  0.115634538900 -0.190087511700 -0.006283021000  0.060939733900
          1.388401188741 -0.434348231700 -0.322839719400 -0.377726982800 -0.224839187800  0.732321580100
          0.496955043655 -0.852791790900 -0.095944016600 -0.454266086000  0.380324658600  0.893564918400
          0.162491615040 -0.242351537800  1.102830348700 -0.257388983000  1.054102919900  0.152954188700
    """

    pseudo_input = f"""\
    #
    H {prefix}AUTO-GTH-PADE-q1 {prefix}AUTO-GTH-LDA-q1 {prefix}AUTO-GTH-PADE {prefix}AUTO-GTH-LDA
        1
         0.20000000    2    -4.18023680     0.72507482
        0

    O {prefix}AUTO-GTH-PADE-q6 {prefix}AUTO-GTH-LDA-q6 {prefix}AUTO-GTH-PADE {prefix}AUTO-GTH-LDA
        2    4
         0.24762086    2   -16.58031797     2.39570092
        2
         0.22178614    1    18.26691718
         0.25682890    0
    """

    BasisSet = DataFactory("gaussian.basisset")  # pylint: disable=invalid-name
    Pseudo = DataFactory("gaussian.pseudo")  # pylint: disable=invalid-name

    fhandle_bset = StringIO(bset_input)
    fhandle_pseudo = StringIO(pseudo_input)

    try:
        bsets = {b.element: b for b in BasisSet.from_cp2k(fhandle_bset, duplicate_handling='error')}
        pseudos = {p.element: p for p in Pseudo.from_cp2k(fhandle_pseudo, duplicate_handling='error')}
    except UniquenessError:  # if the user already ran the script, fetch the data from the db instead
        bsets = {
            "H": BasisSet.get("H", f"{prefix}AUTO-DZVP-MOLOPT-GTH"),
            "O": BasisSet.get("O", f"{prefix}AUTO-DZVP-MOLOPT-SR-GTH"),
        }
        pseudos = {
            "H": Pseudo.get("H", f"{prefix}AUTO-GTH-PADE-q1"),
            "O": Pseudo.get("O", f"{prefix}AUTO-GTH-PADE-q6"),
        }

    return bsets, pseudos
Example #17
0
def cp2k_pseudos(pdataset):
    """Returns pseudo objects from the data above"""
    fhandle = StringIO(PSEUDO_DATA[pdataset])
    Pseudo = DataFactory("gaussian.pseudo")  # pylint: disable=invalid-name
    return {p.element: p for p in Pseudo.from_cp2k(fhandle)}