Exemple #1
0
def test_lammps_potentials_init(
    db_test_app,  # pylint: disable=unused-argument
    get_lammps_potential_data,
    potential_type,
):
    """Test the LAMMPS potential data type."""

    potential_information = get_lammps_potential_data(potential_type)
    node = LammpsPotentialData.get_or_create(
        source=potential_information['filename'],
        filename=potential_information['filename'],
        **potential_information['parameters'],
    )

    reference_file = os.path.join(
        TEST_DIR,
        'test_lammps_potential_data',
        f'test_init_{potential_type}.yaml',
    )

    with io.open(reference_file, 'r') as handler:
        reference_values = yaml.load(handler, yaml.SafeLoader)

    _attributes = [
        'md5', 'pair_style', 'species', 'atom_style', 'default_units'
    ]

    for _attribute in _attributes:
        _msg = f'attribute "{_attribute}" does not match between reference and current value'
        assert reference_values[_attribute] == node.get_attribute(
            _attribute), _msg
Exemple #2
0
def test_lammps_potentials_input_block(
    db_test_app,  # pylint: disable=unused-argument
    get_lammps_potential_data,
    potential_type,
):
    """Test the LAMMPS potential data type."""

    potential_information = get_lammps_potential_data(potential_type)
    node = LammpsPotentialData.get_or_create(
        source=potential_information['filename'],
        filename=potential_information['filename'],
        **potential_information['parameters'],
    )

    potential_block = input_generator.write_potential_block(
        parameters_potential={},
        potential_file='potential.dat',
        potential=node,
        structure=potential_information['structure'],
    )

    reference_file = os.path.join(
        TEST_DIR,
        'test_lammps_potential_data',
        f'test_init_{potential_type}_block.txt',
    )

    with io.open(reference_file, 'r') as handler:
        reference_value = handler.read()

    assert potential_block == reference_value, 'content of the potential blocks differ'
Exemple #3
0
def generate_potential() -> LammpsPotentialData:
    """
    Generate the potential to be used in the calculation.

    Takes a potential form OpenKIM and stores it as a LammpsPotentialData object.

    :return: potential to do the calculation
    :rtype: LammpsPotentialData
    """

    potential_parameters = {
        'species': ['Fe'],
        'atom_style': 'atomic',
        'pair_style': 'eam/fs',
        'units': 'metal',
        'extra_tags': {
            'content_origin':
            'NIST IPRP: https: // www.ctcms.nist.gov/potentials/Fe.html',
            'content_other_locations':
            None,
            'data_method':
            'unknown',
            'description':
            "This Fe EAM potential parameter file is from the NIST repository, \"Fe_2.eam.fs\" as of the March 9, 2009 update. It is similar to \"Fe_mm.eam.fs\" in the LAMMPS distribution dated 2007-06-11, but gives different results for very small interatomic distances (The LAMMPS potential is in fact the deprecated potential referred to in the March 9, 2009 update on the NIST repository). The file header includes a note from the NIST contributor: \"The potential was taken from v9_4_bcc (in C:\\SIMULATION.MD\\Fe\\Results\\ab_initio+Interstitials)\"",
            'developer': ['Ronald E. Miller'],
            'disclaimer':
            'According to the developer Giovanni Bonny (as reported by the NIST IPRP), this potential was not stiffened and cannot be used in its present form for collision cascades.',
            'properties':
            None,
            'publication_year':
            2018,
            'source_citations': [{
                'abstract': None,
                'author':
                'Mendelev, MI and Han, S and Srolovitz, DJ and Ackland, GJ and Sun, DY and Asta, M',
                'doi': '10.1080/14786430310001613264',
                'journal': '{Phil. Mag.}',
                'number': '{35}',
                'pages': '{3977-3994}',
                'recordkey': 'MO_546673549085_000a',
                'recordprimary': 'recordprimary',
                'recordtype': 'article',
                'title':
                '{Development of new interatomic potentials appropriate for crystalline and liquid iron}',
                'volume': '{83}',
                'year': '{2003}'
            }],
            'title':
            'EAM potential (LAMMPS cubic hermite tabulation) for Fe developed by Mendelev et al. (2003) v000'
        }
    }

    potential = LammpsPotentialData.get_or_create(
        source='Fe_2.eam.fs',
        filename='Fe_2.eam.fs',
        **potential_parameters,
    )

    return potential
Exemple #4
0
def write_potential_block(
    potential: LammpsPotentialData,
    structure: orm.StructureData,
    parameters_potential: dict,
    potential_file: str,
) -> str:
    """
    Generate the input block with potential options.

    This will take into consideration the type of potential, as well as other
    parameters which affect the usage of the potential (such as neighbor information)
    and generate a block that is written in the LAMMPS input file.

    :param potential: md-potential which will be used in the calculation
    :type potential: LammpsPotentialData,
    :param structure: structure used for the calculation
    :type structure: orm.StructureData
    :param parameters_potential: parameters which have to deal with the potential
    :type parameters_potential: dict
    :param potential_file: filename for the potential to be used.
    :type str:
    :return: block with the information needed to setup the potential part of
        the LAMMPS calculation.
    :rtype: str
    """

    default_potential = LammpsPotentialData.default_potential_info

    kind_symbols = [kind.symbol for kind in structure.kinds]

    potential_block = generate_header('Start of Potential information')
    potential_block += f'pair_style {potential.pair_style}'
    potential_block += f' {" ".join(parameters_potential.get("potential_style_options", [""]))}\n'

    if default_potential[potential.pair_style].get('read_from_file'):
        potential_block += f'pair_coeff * * {potential_file} {" ".join(kind_symbols)}\n'
    if not default_potential[potential.pair_style].get('read_from_file'):
        data = [
            line for line in potential.get_content().split('\n')
            if not line.startswith('#') and line
        ]
        potential_block += f'pair_coeff * * {" ".join(data)}\n'

    if 'neighbor' in parameters_potential:
        potential_block += f'neighbor {join_keywords(parameters_potential["neighbor"])}\n'
    if 'neighbor_modify' in parameters_potential:
        potential_block += 'neigh_modify'
        potential_block += f' {join_keywords(parameters_potential["neighbor_modify"])}\n'
    potential_block += generate_header('End of Potential information')
    return potential_block
Exemple #5
0
def test_input_generate_minimize(
    db_test_app,  # pylint: disable=unused-argument
    get_lammps_potential_data,
    potential_type,
):
    """Test the generation of the input file for minimize calculations"""
    # pylint: disable=too-many-locals

    parameters_file = os.path.join(
        TEST_DIR,
        'test_generate_inputs',
        'parameters_minimize.yaml',
    )
    # Dictionary with parameters for controlling aiida-lammps
    with open(parameters_file) as handler:
        parameters = yaml.load(handler, yaml.SafeLoader)

    input_generator.validate_input_parameters(parameters)
    # Generate the potential
    potential_information = get_lammps_potential_data(potential_type)
    potential = LammpsPotentialData.get_or_create(
        source=potential_information['filename'],
        filename=potential_information['filename'],
        **potential_information['parameters'],
    )
    # Generating the structure
    structure = potential_information['structure']
    # Generating the input file
    input_file = input_generator.generate_input_file(
        parameters=parameters,
        potential=potential,
        structure=structure,
        trajectory_filename='temp.dump',
        restart_filename='restart.aiida',
        potential_filename='potential.dat',
        structure_filename='structure.dat',
    )
    reference_file = os.path.join(
        TEST_DIR,
        'test_generate_inputs',
        f'test_generate_input_{potential_type}_minimize.txt',
    )

    with io.open(reference_file, 'r') as handler:
        reference_value = handler.read()

    assert input_file == reference_value, 'the content of the files differ'
Exemple #6
0
def test_lammps_potentials_files(
    db_test_app,  # pylint: disable=unused-argument
    get_lammps_potential_data,
    potential_type,
):
    """Test the LAMMPS potential data type."""

    potential_information = get_lammps_potential_data(potential_type)
    node = LammpsPotentialData.get_or_create(
        source=potential_information['filename'],
        filename=potential_information['filename'],
        **potential_information['parameters'],
    )

    _msg = 'content of the files differ'
    assert node.get_content().split(
        '\n') == potential_information['potential_data'].split('\n'), _msg