<commit_before>import sys
import os
import subprocess
import shutil
from uuid import uuid4
from datetime import datetime
from string import Template
from pathlib import Path

from htsohm.material_files import write_mol_file, write_mixing_rules
from htsohm.material_files import write_pseudo_atoms, write_force_field
from htsohm.simulation.files import load_and_subs_template
from htsohm.db import GasLoading

def write_raspa_file(filename, material, simulation_config):
    """Writes RASPA input file for simulating gas adsorption.

    Args:
        filename (str): path to input file.
        material (Material): material record.

    Writes RASPA input-file.

    """
    # Set default void fraction value if non was calculated
    if material.void_fraction[0].void_fraction == None:
        void_fraction = 0.
    else:
        void_fraction = material.void_fraction[0].void_fraction

    # Load simulation parameters from config
    values = {
            "NumberOfCycles"                : simulation_config["simulation_cycles"],
            "NumberOfInitializationCycles"  : simulation_config["initialization_cycles"],
            "FrameworkName"                 : material.uuid,
            "HeliumVoidFraction"            : void_fraction,
            "ExternalTemperature"           : simulation_config["temperature"],
            "ExternalPressure"              : simulation_config["pressure"],
            "MoleculeName"                  : simulation_config["adsorbate"]}

    # Load template and replace values
    input_data = load_and_subs_template("input_file_templates/gas_loading.input", values)

    # Write simulation input-file
    with open(filename, "w") as raspa_input_file:
        raspa_input_file.write(input_data)

def parse_output(output_file, material, simulation_config):
    """Parse output file for gas adsorption data.

    Args:
        output_file (str): path to simulation output file.

    Returns:
        results (dict): absolute and excess molar, gravimetric, and volumetric
            gas loadings, as well as energy of average, van der Waals, and
            Coulombic host-host, host-adsorbate, and adsorbate-adsorbate
            interactions.

    """
    gas_loading = GasLoading()
    gas_loading.adsorbate        = simulation_config["adsorbate"]
    gas_loading.pressure         = simulation_config["pressure"]
    gas_loading.temperature      = simulation_config["temperature"]

    with open(output_file) as origin:
        line_counter = 1
        for line in origin:
            if "absolute [mol/kg" in line:
                gas_loading.absolute_molar_loading = float(line.split()[5])
            elif "absolute [cm^3 (STP)/g" in line:
                gas_loading.absolute_gravimetric_loading = float(line.split()[6])
            elif "absolute [cm^3 (STP)/c" in line:
                gas_loading.absolute_volumetric_loading = float(line.split()[6])
            elif "excess [mol/kg" in line:
                gas_loading.excess_molar_loading = float(line.split()[5])
            elif "excess [cm^3 (STP)/g" in line:
                gas_loading.excess_gravimetric_loading = float(line.split()[6])
            elif "excess [cm^3 (STP)/c" in line:
                gas_loading.excess_volumetric_loading  = float(line.split()[6])
            elif "Average Host-Host energy:" in line:
                host_host_line = line_counter + 8
            elif "Average Adsorbate-Adsorbate energy:" in line:
                adsorbate_adsorbate_line = line_counter + 8
            elif "Average Host-Adsorbate energy:" in line:
                host_adsorbate_line = line_counter + 8
            line_counter += 1

        print("\n{} LOADING : {} v/v (STP)\n".format(simulation_config["adsorbate"],
                                            gas_loading.absolute_volumetric_loading))

    with open(output_file) as origin:
        line_counter = 1<commit_msg>output parent methane loading alongside child<commit_after>import sys
import os
import subprocess
import shutil
from uuid import uuid4
from datetime import datetime
from string import Template
from pathlib import Path

from htsohm.material_files import write_mol_file, write_mixing_rules
from htsohm.material_files import write_pseudo_atoms, write_force_field
from htsohm.simulation.files import load_and_subs_template
from htsohm.db import GasLoading

def write_raspa_file(filename, material, simulation_config):
    """Writes RASPA input file for simulating gas adsorption.

    Args:
        filename (str): path to input file.
        material (Material): material record.

    Writes RASPA input-file.

    """
    # Set default void fraction value if non was calculated
    if material.void_fraction[0].void_fraction == None:
        void_fraction = 0.
    else:
        void_fraction = material.void_fraction[0].void_fraction

    # Load simulation parameters from config
    values = {
            "NumberOfCycles"                : simulation_config["simulation_cycles"],
            "NumberOfInitializationCycles"  : simulation_config["initialization_cycles"],
            "FrameworkName"                 : material.uuid,
            "HeliumVoidFraction"            : void_fraction,
            "ExternalTemperature"           : simulation_config["temperature"],
            "ExternalPressure"              : simulation_config["pressure"],
            "MoleculeName"                  : simulation_config["adsorbate"]}

    # Load template and replace values
    input_data = load_and_subs_template("input_file_templates/gas_loading.input", values)

    # Write simulation input-file
    with open(filename, "w") as raspa_input_file:
        raspa_input_file.write(input_data)

def parse_output(output_file, material, simulation_config):
    """Parse output file for gas adsorption data.

    Args:
        output_file (str): path to simulation output file.

    Returns:
        results (dict): absolute and excess molar, gravimetric, and volumetric
            gas loadings, as well as energy of average, van der Waals, and
            Coulombic host-host, host-adsorbate, and adsorbate-adsorbate
            interactions.

    """
    gas_loading = GasLoading()
    gas_loading.adsorbate        = simulation_config["adsorbate"]
    gas_loading.pressure         = simulation_config["pressure"]
    gas_loading.temperature      = simulation_config["temperature"]

    with open(output_file) as origin:
        line_counter = 1
        for line in origin:
            if "absolute [mol/kg" in line:
                gas_loading.absolute_molar_loading = float(line.split()[5])
            elif "absolute [cm^3 (STP)/g" in line:
                gas_loading.absolute_gravimetric_loading = float(line.split()[6])
            elif "absolute [cm^3 (STP)/c" in line:
                gas_loading.absolute_volumetric_loading = float(line.split()[6])
            elif "excess [mol/kg" in line:
                gas_loading.excess_molar_loading = float(line.split()[5])
            elif "excess [cm^3 (STP)/g" in line:
                gas_loading.excess_gravimetric_loading = float(line.split()[6])
            elif "excess [cm^3 (STP)/c" in line:
                gas_loading.excess_volumetric_loading  = float(line.split()[6])
            elif "Average Host-Host energy:" in line:
                host_host_line = line_counter + 8
            elif "Average Adsorbate-Adsorbate energy:" in line:
                adsorbate_adsorbate_line = line_counter + 8
            elif "Average Host-Adsorbate energy:" in line:
                host_adsorbate_line = line_counter + 8
            line_counter += 1

        print("\n{} LOADING : {} v/v (STP)".format(simulation_config["adsorbate"],
                                            gas_loading.absolute_volumetric_loading))
        if material.parent:
            print("(parent LOADING : {} v/v (STP))".format(material.parent.gas_loading[0].absolute_volumetric_loading))
        print("\n")
    with open(output_file) as origin:
        line_counter = 1
{'fraction_non_alphanumeric': 0.08457400225197047, 'fraction_numerical': 0.005129488302264481, 'mean_word_length': 2.575134168157424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '905866', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2163, 'n_words': 557}