Beispiel #1
0
    def validate_parameters(param_data, potential_object) -> bool:
        """Validate the inputs for an optimization calculation.

        :param param_data: input parameters for the optimization calculations
        :type param_data: orm.Dict
        :param potential_object: LAMMPS potential
        :type potential_object: EmpiricalPotential
        :raises InputValidationError: if there is no parameters data passed
        :raises InputValidationError: if the units of the parameters and
            the potential are different.
        :return: whether the parameters are valid or not
        :rtype: bool
        """
        if param_data is None:
            raise InputValidationError('parameter data not set')
        validate_against_schema(param_data.get_dict(), 'optimize.schema.json')

        # ensure the potential and paramters are in the same unit systems
        # TODO convert between unit systems (e.g. using https://pint.readthedocs.io)
        if 'units' in param_data.get_dict():
            punits = param_data.get_dict()['units']
            if not punits == potential_object.default_units:
                raise InputValidationError(
                    f'the units of the parameters ({punits}) and potential '
                    f'({potential_object.default_units}) are different')

        return True
Beispiel #2
0
    def validate_parameters(param_data, potential_object):
        """Validate the parameters for a force calculation.

        :param param_data: parameters for the LAMMPS force calculation
        :type param_data: orm.Dict
        """
        if param_data is not None:
            validate_against_schema(param_data.get_dict(), 'force.schema.json')
Beispiel #3
0
    def validate_parameters(param_data, potential_object):
        if param_data is None:
            raise InputValidationError('parameter data not set')
        validate_against_schema(param_data.get_dict(), 'md-multi.schema.json')

        # ensure the potential and parameters are in the same unit systems
        # TODO convert between unit systems (e.g. using https://pint.readthedocs.io)
        punits = param_data.get_dict()['units']
        if not punits == potential_object.default_units:
            raise InputValidationError(
                f'the units of the parameters ({punits}) and potential '
                f'({potential_object.default_units}) are different')

        return True
Beispiel #4
0
    def validate_parameters(param_data, potential_object):
        if param_data is None:
            raise InputValidationError("parameter data not set")
        validate_against_schema(param_data.get_dict(), "md.schema.json")

        # ensure the potential and paramters are in the same unit systems
        # TODO convert between unit systems (e.g. using https://pint.readthedocs.io)
        punits = param_data.get_dict()["units"]
        if not punits == potential_object.default_units:
            raise InputValidationError(
                "the units of the parameters ({}) and potential ({}) are different"
                .format(punits, potential_object.default_units))

        return True
Beispiel #5
0
 def validate_data(self, data):
     """Validate the input data."""
     validate_against_schema(data, "reaxff.schema.json")
Beispiel #6
0
def write_lammps_format(data):
    """Write a reaxff file, in lammps format, from a standardised potential dictionary."""
    # validate dictionary
    validate_against_schema(data, "reaxff.schema.json")

    output = [data["description"]]

    # Global parameters
    output.append("{} ! Number of general parameters".format(len(KEYS_GLOBAL)))
    for key in KEYS_GLOBAL:
        output.append("{0:.4f} ! {1}".format(data["global"][key], key))

    # one-body parameters
    output.extend([
        "{0} ! Nr of atoms; cov.r; valency;a.m;Rvdw;Evdw;gammaEEM;cov.r2;#".
        format(len(data["species"])),
        "alfa;gammavdW;valency;Eunder;Eover;chiEEM;etaEEM;n.u.",
        "cov r3;Elp;Heat inc.;n.u.;n.u.;n.u.;n.u.",
        "ov/un;val1;n.u.;val3,vval4",
    ])
    idx_map = {}
    i = 1
    x_species_line = None
    for idx, species in enumerate(data["species"]):
        if species.endswith("shell"):
            raise ValueError(
                "only core species can be used for reaxff, not shell: {}".
                format(species))
        species = species[:-5]
        # X is not always present in 1body, even if it is used in nbody terms
        # see e.g. https://github.com/lammps/lammps/blob/master/potentials/ffield.reax.cho
        if species == "X" and str(idx) not in data["1body"]:
            species_lines = []
        else:
            species_lines = [
                species + " " + " ".join([
                    format_lammps_value(data["1body"][str(idx)][k])
                    for k in KEYS_1BODY[:8]
                ]),
                " ".join([
                    format_lammps_value(data["1body"][str(idx)][k])
                    for k in KEYS_1BODY[8:16]
                ]),
                " ".join([
                    format_lammps_value(data["1body"][str(idx)][k])
                    for k in KEYS_1BODY[16:24]
                ]),
                " ".join([
                    format_lammps_value(data["1body"][str(idx)][k])
                    for k in KEYS_1BODY[24:32]
                ]),
            ]
        if species == "X":
            # X is always index 0, but must be last in the species list
            idx_map[str(idx)] = "0"
            x_species_line = species_lines
        else:
            idx_map[str(idx)] = str(i)
            i += 1
            output.extend(species_lines)
    if x_species_line:
        output.extend(x_species_line)

    # two-body angle parameters
    suboutout = []
    for key in sorted(data["2body"]):
        subdata = data["2body"][key]
        if not set(subdata.keys()).issuperset(KEYS_2BODY_BONDS):
            continue
        suboutout.extend([
            " ".join([idx_map[k]
                      for k in key.split(INDEX_SEP)]) + " " + " ".join([
                          format_lammps_value(subdata[k])
                          for k in KEYS_2BODY_BONDS[:8]
                      ]),
            " ".join([
                format_lammps_value(subdata[k]) for k in KEYS_2BODY_BONDS[8:16]
            ]),
        ])

    output.extend([
        "{0} ! Nr of bonds; Edis1;LPpen;n.u.;pbe1;pbo5;13corr;pbo6".format(
            int(len(suboutout) / 2)),
        "pbe2;pbo3;pbo4;n.u.;pbo1;pbo2;ovcorr",
    ] + suboutout)

    # two-body off-diagonal parameters
    suboutout = []
    for key in sorted(data["2body"]):
        subdata = data["2body"][key]
        if not set(subdata.keys()).issuperset(KEYS_2BODY_OFFDIAG):
            continue
        suboutout.extend([
            " ".join([idx_map[k] for k in key.split(INDEX_SEP)]) + " " +
            " ".join(
                [format_lammps_value(subdata[k]) for k in KEYS_2BODY_OFFDIAG])
        ])

    output.extend([
        "{0} ! Nr of off-diagonal terms; Ediss;Ro;gamma;rsigma;rpi;rpi2".
        format(len(suboutout))
    ] + suboutout)

    # three-body angle parameters
    suboutout = []
    for key in sorted(data["3body"]):
        subdata = data["3body"][key]
        if not set(subdata.keys()).issuperset(KEYS_3BODY_ANGLES):
            continue
        suboutout.extend([
            " ".join([idx_map[k] for k in key.split(INDEX_SEP)]) + " " +
            " ".join(
                [format_lammps_value(subdata[k]) for k in KEYS_3BODY_ANGLES])
        ])

    output.extend([
        "{0} ! Nr of angles;at1;at2;at3;Thetao,o;ka;kb;pv1;pv2".format(
            len(suboutout))
    ] + suboutout)

    # four-body torsion parameters
    suboutout = []
    for key in sorted(data["4body"]):
        subdata = data["4body"][key]
        if not set(subdata.keys()).issuperset(KEYS_4BODY_TORSION):
            continue
        suboutout.extend([
            " ".join([idx_map[k] for k in key.split(INDEX_SEP)]) + " " +
            " ".join(
                [format_lammps_value(subdata[k]) for k in KEYS_4BODY_TORSION])
        ])

    output.extend([
        "{0} ! Nr of torsions;at1;at2;at3;at4;;V1;V2;V3;V2(BO);vconj;n.u;n".
        format(len(suboutout))
    ] + suboutout)

    # three-body h-bond parameters
    suboutout = []
    for key in sorted(data["3body"]):
        subdata = data["3body"][key]
        if not set(subdata.keys()).issuperset(KEYS_3BODY_HBOND):
            continue
        suboutout.extend([
            " ".join([idx_map[k] for k in key.split(INDEX_SEP)]) + " " +
            " ".join(
                [format_lammps_value(subdata[k]) for k in KEYS_3BODY_HBOND])
        ])

    output.extend([
        "{0} ! Nr of hydrogen bonds;at1;at2;at3;Rhb;Dehb;vhb1".format(
            len(suboutout))
    ] + suboutout)

    output.append("")

    return "\n".join(output)
Beispiel #7
0
 def validate_parameters(param_data, potential_object):
     if param_data is not None:
         validate_against_schema(param_data.get_dict(), "force.schema.json")