def test_optimize_process( db_test_app, get_potential_data, potential_type, data_regression, ): """Test the functionality of the optimization calculation type""" calc_plugin = 'lammps.optimize' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory('lammps.potential')( potential_type=pot_data.type, data=pot_data.data, ) parameters = get_calc_parameters( get_lammps_version(code), calc_plugin, potential.default_units, potential_type, ) builder = code.get_builder() builder._update({ # pylint: disable=protected-access 'metadata': tests.get_default_metadata(), 'code': code, 'structure': pot_data.structure, 'potential': potential, 'parameters': parameters, }) output = run_get_node(builder) calc_node = output.node if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception( f'finished with exit message: {calc_node.exit_message}') link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset( ['results', 'trajectory_data', 'structure']) trajectory_data = calc_node.outputs.trajectory_data.attributes # optimization steps may differ between lammps versions trajectory_data = { k: v for k, v in trajectory_data.items() if k != 'number_steps' } data_regression.check({ 'results': sanitize_results(calc_node.outputs.results.get_dict(), 1), 'trajectory_data': trajectory_data, 'structure': { 'kind_names': calc_node.outputs.structure.get_kind_names() } # "structure": tests.recursive_round( # calc_node.outputs.structure.attributes, 1, apply_lists=True # ), })
def test_md_submission(db_test_app, get_potential_data, potential_type): """Test the submission of the md type of calculation""" calc_plugin = 'lammps.md' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory('lammps.potential')( potential_type=pot_data.type, data=pot_data.data, ) parameters = get_calc_parameters( get_lammps_version(code), calc_plugin, potential.default_units, potential_type, ) builder = code.get_builder() builder._update({ # pylint: disable=protected-access 'metadata': tests.get_default_metadata(), 'code': code, 'structure': pot_data.structure, 'potential': potential, 'parameters': parameters, }) with db_test_app.sandbox_folder() as folder: calc_info = db_test_app.generate_calcinfo(calc_plugin, folder, builder) assert calc_info.codes_info[0].cmdline_params == ['-in', 'input.in'] assert set(folder.get_content_list()).issuperset( ['input.data', 'input.in'])
def test_md_process( db_test_app, get_potential_data, potential_type, data_regression, ): """Test the functionality of the md calculation type""" calc_plugin = 'lammps.md' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory('lammps.potential')( potential_type=pot_data.type, data=pot_data.data, ) version = get_lammps_version(code) version_year = version[-4:] parameters = get_calc_parameters( version, calc_plugin, potential.default_units, potential_type, ) builder = code.get_builder() builder._update({ # pylint: disable=protected-access 'metadata': tests.get_default_metadata(), 'code': code, 'structure': pot_data.structure, 'potential': potential, 'parameters': parameters, }) output = run_get_node(builder) calc_node = output.node if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception( f'finished with exit message: {calc_node.exit_message}') link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset( ['results', 'trajectory_data', 'system_data']) data_regression.check( { 'results': sanitize_results( calc_node.outputs.results.get_dict(), round_energy=1, ), 'system_data': calc_node.outputs.system_data.attributes, 'trajectory_data': calc_node.outputs.trajectory_data.attributes, }, basename=f'test_md_process-{potential_type}-{version_year}', )
def test_md_multi_process( db_test_app, get_potential_data, potential_type, data_regression ): calc_plugin = "lammps.md.multi" code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters( get_lammps_version(code), calc_plugin, potential.default_units, potential_type ) builder = code.get_builder() builder._update( { "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters, } ) output = run_get_node(builder) calc_node = output.node if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception("finished with exit message: {}".format(calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset( [ "results", "retrieved", "trajectory__thermalise", "trajectory__equilibrate", "system__thermalise", "system__equilibrate", ] ) data_regression.check( { "retrieved": calc_node.outputs.retrieved.list_object_names(), "results": sanitize_results( calc_node.outputs.results.get_dict(), round_energy=1 ), "system__thermalise": calc_node.outputs.system__thermalise.attributes, "system__equilibrate": calc_node.outputs.system__equilibrate.attributes, "trajectory__thermalise": calc_node.outputs.trajectory__thermalise.attributes, "trajectory__equilibrate": calc_node.outputs.trajectory__equilibrate.attributes, } )
def test_force_process( db_test_app, get_potential_data, potential_type, data_regression, ): """Test the functionality of the force calculation type""" calc_plugin = 'lammps.force' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory('lammps.potential')( potential_type=pot_data.type, data=pot_data.data, ) parameters = get_calc_parameters( get_lammps_version(code), calc_plugin, potential.default_units, potential_type, ) builder = code.get_builder() builder._update({ # pylint: disable=protected-access 'metadata': tests.get_default_metadata(), 'code': code, 'structure': pot_data.structure, 'potential': potential, 'parameters': parameters, }) output = run_get_node(builder) calc_node = output.node # raise ValueError(calc_node.get_object_content('input.in')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('_scheduler-stdout.txt')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('trajectory.lammpstrj')) if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception('finished with exit message: {}'.format( calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset(['results', 'arrays']) data_regression.check({ 'results': sanitize_results(calc_node.outputs.results.get_dict(), 1), 'arrays': calc_node.outputs.arrays.attributes, })
def test_force_process(db_test_app, get_potential_data, potential_type): calc_plugin = 'lammps.force' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(structure=pot_data.structure, type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters(calc_plugin, potential.default_units, potential_type) builder = code.get_builder() builder._update({ "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters }) output = run_get_node(builder) calc_node = output.node # raise ValueError(calc_node.get_object_content('input.in')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('_scheduler-stdout.txt')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('trajectory.lammpstrj')) if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception("finished with exit message: {}".format( calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset(['results', 'arrays']) pdict = calc_node.outputs.results.get_dict() assert set(pdict.keys()).issuperset([ 'energy', 'warnings', 'final_variables', 'units_style', 'energy_units', 'force_units', 'parser_class', 'parser_version' ]) assert pdict['warnings'].strip() == pot_data.output["warnings"] assert pdict['energy'] == pytest.approx(pot_data.output['initial_energy']) if potential_type == "reaxff": assert set(calc_node.outputs.arrays.get_arraynames()) == set( ['forces', 'charges']) else: assert set(calc_node.outputs.arrays.get_arraynames()) == set( ['forces']) assert calc_node.outputs.arrays.get_shape('forces') == ( 1, len(pot_data.structure.sites), 3)
def test_optimize_process(db_test_app, get_potential_data, potential_type, data_regression): calc_plugin = "lammps.optimize" code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters(get_lammps_version(code), calc_plugin, potential.default_units, potential_type) builder = code.get_builder() builder._update({ "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters, }) output = run_get_node(builder) calc_node = output.node if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception("finished with exit message: {}".format( calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset( ["results", "trajectory_data", "structure"]) trajectory_data = calc_node.outputs.trajectory_data.attributes # optimization steps may differ between lammps versions trajectory_data = { k: v for k, v in trajectory_data.items() if k != "number_steps" } data_regression.check({ "results": sanitize_results(calc_node.outputs.results.get_dict(), 1), "trajectory_data": trajectory_data, "structure": { "kind_names": calc_node.outputs.structure.get_kind_names() } # "structure": tests.recursive_round( # calc_node.outputs.structure.attributes, 1, apply_lists=True # ), })
def test_md_process(db_test_app, get_potential_data, potential_type): calc_plugin = 'lammps.md' code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(structure=pot_data.structure, type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters(calc_plugin, potential.default_units, potential_type) builder = code.get_builder() builder._update({ "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters, }) output = run_get_node(builder) calc_node = output.node if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception("finished with exit message: {}".format( calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset( ['results', 'trajectory_data', 'system_data']) pdict = calc_node.outputs.results.get_dict() assert set(pdict.keys()).issuperset( ['warnings', 'parser_class', 'parser_version']) assert pdict['warnings'].strip() == pot_data.output["warnings"] if potential_type == "reaxff": assert set(calc_node.outputs.trajectory_data.get_arraynames()) == set( ['cells', 'positions', 'steps', 'times', 'charges']) assert set(calc_node.outputs.system_data.get_arraynames()) == set( ['step', 'temp', 'etotal', 'c_reax_1_']) else: assert set(calc_node.outputs.trajectory_data.get_arraynames()) == set( ['cells', 'positions', 'steps', 'times']) assert set(calc_node.outputs.system_data.get_arraynames()) == set( ['step', 'temp', 'etotal']) assert calc_node.outputs.trajectory_data.numsteps == 101 assert calc_node.outputs.system_data.get_shape('temp') == (100, )
def test_force_process( db_test_app, get_potential_data, potential_type, data_regression ): calc_plugin = "lammps.force" code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters( get_lammps_version(code), calc_plugin, potential.default_units, potential_type ) builder = code.get_builder() builder._update( { "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters, } ) output = run_get_node(builder) calc_node = output.node # raise ValueError(calc_node.get_object_content('input.in')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('_scheduler-stdout.txt')) # raise ValueError(calc_node.outputs.retrieved.get_object_content('trajectory.lammpstrj')) if not calc_node.is_finished_ok: print(calc_node.attributes) print(get_calcjob_report(calc_node)) raise Exception("finished with exit message: {}".format(calc_node.exit_message)) link_labels = calc_node.get_outgoing().all_link_labels() assert set(link_labels).issuperset(["results", "arrays"]) data_regression.check( { "results": sanitize_results(calc_node.outputs.results.get_dict(), 1), "arrays": calc_node.outputs.arrays.attributes, } )
def test_md_submission(db_test_app, get_potential_data, potential_type): calc_plugin = "lammps.md" code = db_test_app.get_or_create_code(calc_plugin) pot_data = get_potential_data(potential_type) potential = DataFactory("lammps.potential")(type=pot_data.type, data=pot_data.data) parameters = get_calc_parameters(get_lammps_version(code), calc_plugin, potential.default_units, potential_type) builder = code.get_builder() builder._update({ "metadata": tests.get_default_metadata(), "code": code, "structure": pot_data.structure, "potential": potential, "parameters": parameters, }) with db_test_app.sandbox_folder() as folder: calc_info = db_test_app.generate_calcinfo(calc_plugin, folder, builder) assert calc_info.codes_info[0].cmdline_params == ["-in", "input.in"] assert set(folder.get_content_list()).issuperset( ["input.data", "input.in"])