def testNoGrowth(self): # Here, all the monomers are available at the beginning of the simulation try: # minimize random calls by providing set list of monomer types mono_type_list = [ S, S, S, S, G, S, S, S, S, S, S, G, S, S, S, S, S, S, S, S, S, S, S, S ] random_num = 24 initial_monomers = [ Monomer(mono_type, i) for i, mono_type in enumerate(mono_type_list) ] initial_events = create_initial_events(initial_monomers, DEF_RXN_RATES) initial_state = create_initial_state(initial_events, initial_monomers) # since GROW is not added to event_dict, no additional monomers will be added result = run_kmc(DEF_RXN_RATES, initial_state, sorted(initial_events), t_max=0.0001, random_seed=random_num) gen_tcl(result[ADJ_MATRIX], result[MONO_LIST], tcl_fname=TCL_FNAME, chain_id="L", out_dir=SUB_DATA_DIR) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_NO_GROW_OUT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def testMakeTCL(self): try: silent_remove(TCL_FILE_LOC) result = create_sample_kmc_result() gen_tcl(result[ADJ_MATRIX], result[MONO_LIST], tcl_fname=TCL_FNAME, chain_id="L", toppar_dir='toppar', out_dir=SUB_DATA_DIR) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_OUT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def testMakeTCLCLignin(self): # Only adds 3 lines to coverage... oh well! At least it's quick. try: seed = 1 monos = 7 silent_remove(TCL_FILE_LOC) result = create_sample_kmc_result_c_lignin(num_monos=monos, max_monos=monos*2, seed=seed) good_last_time = 0.004474718478040326 self.assertAlmostEqual(result[TIME][-1], good_last_time) gen_tcl(result[ADJ_MATRIX], result[MONO_LIST], tcl_fname=TCL_FNAME, chain_id="L", toppar_dir=None, out_dir=SUB_DATA_DIR) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_C_LIGNIN_OUT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def produce_output(adj_matrix, mono_list, cfg): if cfg[SUPPRESS_SMI] and not (cfg[SAVE_JSON] or cfg[SAVE_PNG] or cfg[SAVE_SVG]): format_list = [SAVE_TCL] mol = None # Make IDE happy else: # Default out is SMILES, which requires getting an rdKit molecule object; also required for everything # except the TCL format format_list = [SAVE_TCL, SAVE_JSON, SAVE_PNG, SAVE_SVG] block = generate_mol(adj_matrix, mono_list) mol = MolFromMolBlock(block) try: smi_str = MolToSmiles(mol) + '\n' except: raise InvalidDataError("Error in producing SMILES string.") # if SMI is to be saved, don't output to stdout if cfg[SAVE_SMI]: fname = create_out_fname(cfg[BASENAME], base_dir=cfg[OUT_DIR], ext=SAVE_SMI) str_to_file(smi_str, fname, print_info=True) else: print("\nSMILES representation: \n", MolToSmiles(mol), "\n") if cfg[SAVE_PNG] or cfg[SAVE_SVG] or cfg[SAVE_JSON]: # PNG and SVG make 2D images and thus need coordinates # JSON will save coordinates--zero's if not computed; might as well compute and save non-zero values Compute2DCoords(mol) for save_format in format_list: if cfg[save_format]: fname = create_out_fname(cfg[BASENAME], base_dir=cfg[OUT_DIR], ext=save_format) if save_format == SAVE_TCL: gen_tcl(adj_matrix, mono_list, tcl_fname=fname, chain_id=cfg[CHAIN_ID], psf_fname=cfg[PSF_FNAME], toppar_dir=cfg[TOPPAR_DIR], out_dir=cfg[OUT_DIR]) if save_format == SAVE_JSON: json_str = MolToJSON(mol) str_to_file(json_str + '\n', fname) elif save_format == SAVE_PNG or save_format == SAVE_SVG: MolToFile(mol, fname, size=cfg[IMAGE_SIZE]) print(f"Wrote file: {fname}")
initial_monomers = create_initial_monomers(pct_s, monomer_draw) # Initially allow only oxidation events. After they are used to determine the initial state, add # GROW to the events, which allows additional monomers to be added to the reaction at the # specified rate and with the specified ratio initial_events = create_initial_events(initial_monomers, rxn_rates) initial_state = create_initial_state(initial_events, initial_monomers) initial_events.append(Event(GROW, [], rate=mono_add_rate)) result = run_kmc(rxn_rates, initial_state, initial_events, n_max=max_num_monos, t_max=t_max, sg_ratio=sg_ratio) # Convert the sparse matrix to a full array before printing print("The adjacency matrix for the simulated lignin is:") print(result[ADJ_MATRIX].toarray()) # From the list of monomers and the adjacency matrix, we can use LigninKMC to write out a tcl script for psfgen to # turn into a .psf file. # fname and sgnames are things that we'd want to change; file name always the same as the segname gen_tcl(result[ADJ_MATRIX], result[MONO_LIST], toppar_dir="../smilesdemo/toppar/", tcl_fname="psfgen.tcl", psf_fname="L", chain_id="L") # Now we switch over into vmd...