Exemplo n.º 1
0
try:
    os.chdir(args.work_dir)
except OSError:
    os.mkdir(args.work_dir)
    os.chdir(args.work_dir)
for ng in number_of_gens:
    gen_name = str(args.population_size)+"_"+str(ng)
    print "Running "+gen_name
    p_name = gen_name+"_gen.p"
    if ng == 1:
        #initial setup, pop_size, mol_coords and com_files
        smiles_string = 'c1ccc2cc3cc4cc5ccccc5cc4cc3cc2c1'
        mixed_pop = []
        n_numbers = [6,7,8,9,10]
        for n in n_numbers:
            pop = ga_setup_selection.generate_initial_population(smiles_string,20,n)
            print len(pop)
            mixed_pop += pop
        print len(mixed_pop)
#        pop = ga_setup_selection.generate_initial_population(smiles_string,args.population_size,args.nitrogen_number)
        #print len(pop)
        mol_lst = ga_setup_selection.mol_name_maker(mixed_pop)
        #writing generation .p
        ga_setup_selection.init_gen_dumper(p_name,mol_lst)
        #collecting and running coms
        all_mol_coords = ga_setup_selection.coords_generator(mol_lst)
        if args.gauss_calc == "reorg_en" or "reorg_en+ea":
            gen_result = ga_gauss.reorg_en_calc(all_mol_coords)
        if args.gauss_calc == "hl_diff":
            gen_result = ga_gauss.hl_diff_calc(all_mol_coords)
        if args.gauss_calc == "max_dipole":
Exemplo n.º 2
0
print "Beginning ga run with " + str(
    args.population_size) + " pop members for " + str(
        args.number_of_gens) + " generations"
try:
    os.chdir(args.work_dir)
except OSError:
    os.mkdir(args.work_dir)
    os.chdir(args.work_dir)
for ng in number_of_gens:
    gen_name = str(args.population_size) + "_" + str(ng)
    print "Running " + gen_name
    p_name = gen_name + "_gen.p"
    if ng == 1:
        #initial setup, pop_size, mol_coords and com_files
        smiles_string = 'c1ccc2cc3cc4cc5ccccc5cc4cc3cc2c1'
        pop = ga_setup_selection.generate_initial_population(
            smiles_string, args.population_size, args.nitrogen_number)
        #print len(pop)
        mol_lst = ga_setup_selection.mol_name_maker(pop)
        #writing generation .p
        ga_setup_selection.init_gen_dumper(p_name, mol_lst)
        #collecting and running coms
        all_mol_coords = ga_setup_selection.coords_generator(mol_lst)
        if args.gauss_calc == "reorg_en":
            gen_result = ga_gauss.reorg_en_calc(all_mol_coords)
        if args.gauss_calc == "hl_diff":
            gen_result = ga_gauss.hl_diff_calc(all_mol_coords)
        if args.gauss_calc == "max_dipole":
            gen_result = ga_gauss.max_dipole_calc(all_mol_coords)
        if args.gauss_calc == "lumo":
            gen_result = ga_gauss.lumo_calc(all_mol_coords)
        print gen_result
parser.add_argument("-n_gen", "--number_of_generations", type=int, help="how many generations to run for", default=5)

args = parser.parse_args()



gen_counter = 1
gen_name = str(args.population_size)+"_"+str(gen_counter)
smiles_string = 'c1ccc2cc3cc4cc5ccccc5cc4cc3cc2c1'
#temp_list = list(smiles_string)
#mutant = ga_setup_selection.mutator(temp_list, mutation_factor = 10, N_number=5)
#mutant_string = ''.join(mutant)
#m3 = Chem.MolFromSmiles(mutant_string)
#print mutant_string
#if args.setup_ga_run == "Y":
    pop = ga_setup_selection.generate_initial_population(smiles_string,args.population_size,args.nitrogen_number)
    print len(pop)
    mol_lst = ga_setup_selection.mol_name_maker(pop)
    all_mol_coords = ga_setup_selection.coords_generator(mol_lst)
    print len(all_mol_coords)
    ga_setup_selection.com_generator_neutral_grndst(all_mol_coords)
    #ga_setup_selection.com_generator_neg_mol_neg_geom(all_mol_coords)
    dump_list = []
    for m in mol_lst:
        name = m.GetProp("_Name")
        pm = AllChem.PropertyMol(m)
        pm.SetProp("_Name", name)
        pm.SetProp("_Energy", None)
        dump_list.append(pm)
    cPickle.dump(dump_list, open(gen_name)+"_gen.p", "w+")