def convert_to_class(materials=None): ''' Function to convert a material's string representation to it's class representation. ''' (material_names, material_objects) = get_materials() all_material_classes = [] # iterate through each material in the list of provided material strings for material in materials: # get the index of the current material in the list of names from get_materials; # obtain the class representation of the material using the index material_class = None for i, material_name in enumerate(material_names): if any([ material_name == material, material_objects[i]().get_name() == material ]): material_class = material_objects[i] # append the class representation of the current material to a list all_material_classes.append(material_class) return all_material_classes
def convert_volume_to_mol(mat, volume, unit='l'): if type(mat) == material.Material: mass = convert_volume(volume, unit) * mat().get_density() return mass / mat.get_molar_mass() elif type(mat) == str: found = False materials = material.get_materials() for i, name in enumerate(materials[0]): if name == mat: found = True mass = convert_volume(volume, unit) * materials[1][i]().get_density() return mass / materials[1][i]().get_molar_mass() if not found: raise ValueError('Material name not found') else: raise TypeError('the material input must be a material class or a string name for the material')
import itertools import sys # ensure all necessary modules can be found sys.path.append("../") # to access chemistrylab sys.path.append("../chemistrylab/reactions") # to access all reactions # import all local modules import chemistrylab # import the materials file from chemistrylab.chem_algorithms import material # take the materials from the material.py file (materials, mat_objects) = material.get_materials() # -------------------- # INPUT MATERIALS # -------------------- # # define the chloro hydrocarbons available all_chloro = [ material for material in materials if "chloro" in material.lower() ] # reaction_bench requires at least one chloro hydrocarbon and Na to generate a Wurtz reaction; # additionally, a single solute must be used as well; # all possible valid configurations are generated and tabulated below available_input_materials = [] for i, __ in enumerate(all_chloro): # create a list of every combination of available chloro-hydrocarbons