Ejemplo n.º 1
0
def test_void_fraction_one_sphere_across_pbc():
    atoms = [(0, 0, 0, 2)]
    assert calculate_void_fraction(atoms, (4, 4, 4)) == approx(
        1 - r1volume / 4**3, 0.01)

    atoms = [(4, 4, 4, 2)]
    assert calculate_void_fraction(atoms, (4, 4, 4)) == approx(
        1 - r1volume / 4**3, 0.01)
Ejemplo n.º 2
0
def test_void_fraction_one_sphere():
    atoms = [(2, 2, 2, 2)]
    # NOTE on approx void fraction calculations:
    # the volume of one sphere of radius r = 1 is equal to r1volume. The % of the volume taken up by
    # the sphere is equal to r1volume / box volume = r1volume/4**3
    assert calculate_void_fraction(atoms, (4, 4, 4)) == approx(
        1 - r1volume / 4**3, 0.01)
Ejemplo n.º 3
0
def run(material, simulation_config, config):
    """Runs void fraction simulation.

    Args:
        material (Material): material record.

    Returns:
        results (dict): void fraction simulation results.

    """
    output_dir = "output_{}_{}".format(material.uuid, uuid4())
    slog("Output directory : {}".format(output_dir))
    os.makedirs(output_dir, exist_ok=True)

    write_output_files(material, simulation_config, output_dir)

    # Run simulations
    slog("Probe            : {}".format(simulation_config["adsorbate"]))
    if "do_geo" in simulation_config:
        slog("Probe radius [geo]: {}".format(simulation_config["probe_radius"]))
    slog("Temperature      : {}".format(simulation_config["temperature"]))

    void_fraction = VoidFraction()
    void_fraction.adsorbate = simulation_config["adsorbate"]
    void_fraction.temperature = simulation_config["temperature"]

    if "do_raspa" in simulation_config and simulation_config["do_raspa"]:
        tbegin = time.perf_counter()
        process = subprocess.run(["simulate", "-i", "./void_fraction.input"], check=True, cwd=output_dir, capture_output=True, text=True)

        data_files = glob(os.path.join(output_dir, "Output", "System_0", "*.data"))
        if len(data_files) != 1:
            raise Exception("ERROR: There should only be one data file in the output directory for %s. Check code!" % output_dir)
        output_file = data_files[0]

        # Parse output
        parse_output(output_file, material, void_fraction)
        slog("RASPA void fraction simulation time: %5.2f seconds" % (time.perf_counter() - tbegin))
        slog("RASPA VOID FRACTION : {}".format(void_fraction.void_fraction))
        if material.parent:
            slog("(parent VOID FRACTION : {})".format(material.parent.void_fraction[0].void_fraction))


    # run geometric void fraction
    if "do_geo" in simulation_config and simulation_config["do_geo"]:
        tbegin = time.perf_counter()
        atoms = [(a.x * material.structure.a, a.y * material.structure.b, a.z * material.structure.c, a.atom_types.sigma) for a in material.structure.atom_sites]
        box = (material.structure.a, material.structure.b, material.structure.c)
        void_fraction.void_fraction_geo = calculate_void_fraction(atoms, box, probe_r=simulation_config["probe_radius"])
        slog("GEOMETRIC void fraction: %f" % void_fraction.void_fraction_geo)
        slog("GEOMETRIC void fraction simulation time: %5.2f   seconds" % (time.perf_counter() - tbegin))
    if "do_zeo" in simulation_config:
        pass
        # run zeo void fraction here

    material.void_fraction.append(void_fraction)

    if not config['keep_configs']:
        shutil.rmtree(output_dir, ignore_errors=True)
    sys.stdout.flush()
Ejemplo n.º 4
0
def test_void_fraction_two_separate_spheres():
    atoms = [(1, 1, 1, 2),
             (2.9, 2.9, 2.9, 2)]  #2.9 so it doesn't hit the right boundary
    assert calculate_void_fraction(atoms, (4, 4, 4)) == approx(
        1 - 2 * r1volume / 4**3, 0.01)
Ejemplo n.º 5
0
def test_void_fraction_two_identical_spheres():
    atoms = [(2, 2, 2, 2), (2, 2, 2, 2)]
    assert calculate_void_fraction(atoms, (4, 4, 4)) == approx(
        1 - r1volume / 4**3, 0.01)
Ejemplo n.º 6
0
def test_void_fraction_one_sphere_w_he_probe():
    atoms = [(2, 2, 2, 2)]
    assert calculate_void_fraction(atoms, (4, 4, 4), probe_r=1.0) == approx(
        1 - r1volume * 2**3 / 4**3, 0.01)
Ejemplo n.º 7
0
def test_void_fraction_huger_atom():
    assert calculate_void_fraction([(2, 2, 2, 100)], (4, 4, 4),
                                   points_per_angstrom=2) == 0.0
Ejemplo n.º 8
0
def test_void_fraction_empty_crystal():
    assert calculate_void_fraction([], (4, 4, 4)) == 1.0