Beispiel #1
0
def mutate_and_relax(candidate, name, iteration, cnt_max, **kwargs):
    print_output("__%s__" % name)
    found = False
    cnt = 0
    while found is False and cnt < cnt_max:
        candidate_backup = Structure(candidate)
        candidate.mutate(**kwargs)
        print_output("%s after mutation: " % name + str(candidate))
        run_util.str_info(candidate)
        if not candidate.is_geometry_valid():
            print_output(" The geometry of %s is invalid." % name)
            cnt += 1
            # Rebuild the structure
            candidate = candidate_backup
            continue

        if candidate not in blacklist:
            name = "generation_%d_%s" % (iteration, name)
            run_util.optimize(candidate, energy_function, params, name)
            run_util.check_for_kill()
            candidate.send_to_blacklist(blacklist)
            print_output(str(candidate)+":, energy: "+str(float(
                candidate))+", is temporary added to the population")
            run_util.relax_info(candidate)
            found = True
            population.append(candidate)
        else:
            print_output("Geomerty of "+str(candidate)+" is fine, but already "
                         "known.")
            cnt += 1
            candidate = candidate_backup
        if cnt == cnt_max:
            raise Exception("The allowed number of trials for generating"
                            " a unique child has been exceeded.")
Beispiel #2
0
def mutate_and_relax(candidate, name, iteration, cnt_max, **kwargs):
    print_output("__%s__" % name)
    found = False
    cnt = 0
    while found is False and cnt < cnt_max:
        candidate_backup = Structure(candidate)
        candidate.mutate(**kwargs)
        print_output("%s after mutation: " % name + str(candidate))
        run_util.str_info(candidate)
        if not candidate.is_geometry_valid():
            print_output(" The geometry of %s is invalid." % name)
            cnt += 1
            # Rebuild the structure
            candidate = candidate_backup
            continue

        if candidate not in blacklist:
            name = "generation_%d_%s" % (iteration, name)
            run_util.optimize(candidate, energy_function, params, name)
            run_util.check_for_kill()
            candidate.send_to_blacklist(blacklist)
            print_output(
                str(candidate) + ":, energy: " + str(float(candidate)) +
                ", is temporary added to the population")
            run_util.relax_info(candidate)
            found = True
            population.append(candidate)
        else:
            print_output("Geomerty of " + str(candidate) +
                         " is fine, but already "
                         "known.")
            cnt += 1
            candidate = candidate_backup
        if cnt == cnt_max:
            raise Exception("The allowed number of trials for generating"
                            " a unique child has been exceeded.")
Beispiel #3
0
def mutate_and_relax(candidate, name, prob_for_mut_torsions,
                     prob_for_mut_cistrans, max_mutations_torsions,
                     max_mutations_cistrans, iteration, cnt_max):
    print_output("__%s__" % name)
    found = False
    cnt = 0
    while found is False and cnt < cnt_max:
        mut1, mut2 = np.random.rand(), np.random.rand()
        candidate_backup = Structure(candidate)
        if mut1 < prob_for_mut_torsions:
            candidate.mutation_tor(max_mutations_torsions)
            print_output("%s after mutation in torsions: " % name + str(
                    candidate))
        if mut2 < prob_for_mut_cistrans:
            candidate.mutation_cistrans(max_mutations_cistrans)
            print_output("%s after mutation in cistrans: " % name + str(
                    candidate))
        if not candidate.is_geometry_valid():
            print_output(" The geometry of %s is invalid." % name)
            cnt += 1
            candidate = candidate_backup
            continue
        if candidate not in blacklist:
            name = "generation_%d_%s" % (iteration, name)
            candidate.perform_ff(p_file)
            candidate.send_to_blacklist(black_dir, blacklist)
            print_output(str(candidate)+":, energy: "+str(float(
                candidate))+", is temporary added to the population")
            found = True
            population.append(candidate)
        else:
            print_output("Geomerty fine, but the structure already known")
            cnt += 1
            candidate = candidate_backup
        if cnt == cnt_max:
            raise Exception("The allowed number of trials for generating a"
                            " unique child has been exceeded.")
Beispiel #4
0
prob_for_mut_torsions = float(p_dict['prob_for_mut_torsions'])
max_mutations_cistrans = int(p_dict['max_mutations_cistrans'])
max_mutations_torsions = int(p_dict['max_mutations_torsions'])
iter_limit_conv = int(p_dict['iter_limit_conv'])
energy_diff_conv = float(p_dict['energy_diff_conv'])
energy_wanted = float(p_dict['energy_wanted'])

cnt_max = 100

mol = MoleculeDescription(p_file)
mol.get_mol_parameters()
mol.create_template_sdf()

population, blacklist = [], []
min_energy = []
print_output("___Initialization___")
cnt = 0
while len(population) < popsize and cnt < cnt_max:
    print_output("New trial")
    str3d = Structure(mol)
    str3d.generate_random_structure(cistrans1, cistrans2)
    if not str3d.is_geometry_valid():
        print_output("The geometry of "+str(str3d)+" is invalid.")
        cnt += 1
        continue
    if str3d not in blacklist:
        name = "initial_%d" % (len(population))
        str3d.perform_ff(p_file)
        str3d.send_to_blacklist(black_dir, blacklist)
        population.append(str3d)
        print_output(str(str3d)+", energy: "+str(float(str3d)) +
Beispiel #5
0
# Set defaults for parameters not defined in the parameter file.
params = set_default(params, dict_default)
energy_function = run_util.detect_energy_function(params)

cnt_max = 200
population, blacklist = [], []
min_energy = []

if opt == "simple":
    mol = MoleculeDescription(p_file)
    # Assign the permanent attributes to the molecule.
    mol.get_parameters()
    mol.create_template_sdf()
    # Check for potential degree of freedom related parameters.
    linked_params = run_util.find_linked_params(mol, params)
    print_output("Number of atoms: " + str(mol.atoms))
    print_output("Number of bonds: " + str(mol.bonds))
    for dof in mol.dof_names:
        print_output("Number of identified " + str(dof) + ": " +
                     str(len(getattr(mol, dof))))
        print_output("Identified " + str(dof) + ": " + str(getattr(mol, dof)))

    print_output("___Initialization___")
    cnt = 0
    # Generate sensible and unique 3d structures.
    while len(population) < params['popsize'] and cnt < cnt_max:
        print_output("New trial")
        str3d = Structure(mol)
        str3d.generate_structure()
        if not str3d.is_geometry_valid():
            print_output("The geometry of " + str(str3d) + " is invalid.")
Beispiel #6
0
# Set defaults for parameters not defined in the parameter file.
params = set_default(params, dict_default)
energy_function = run_util.detect_energy_function(params)

cnt_max = 200
population, blacklist = [], []
min_energy = []

if opt == "simple":
    mol = MoleculeDescription(p_file)
    # Assign the permanent attributes to the molecule.
    mol.get_parameters()
    mol.create_template_sdf()
    # Check for potential degree of freedom related parameters.
    linked_params = run_util.find_linked_params(mol, params)
    print_output("Number of atoms: "+str(mol.atoms))
    print_output("Number of bonds: "+str(mol.bonds))
    for dof in mol.dof_names:
        print_output("Number of identified "+str(dof)+": " +
                     str(len(getattr(mol, dof))))
        print_output("Identified "+str(dof)+": "+str(getattr(mol, dof)))

    print_output("___Initialization___")
    cnt = 0
    # Generate sensible and unique 3d structures.
    while len(population) < params['popsize'] and cnt < cnt_max:
        print_output("New trial")
        str3d = Structure(mol)
        str3d.generate_structure()
        if not str3d.is_geometry_valid():
            print_output("The geometry of "+str(str3d)+" is invalid.")
Beispiel #7
0
fitness_sum_limit = str(p_dict['fitness_sum_limit'])
prob_for_crossing = float(p_dict['prob_for_crossing'])
prob_for_mut_cistrans = float(p_dict['prob_for_mut_cistrans'])
prob_for_mut_torsions = float(p_dict['prob_for_mut_torsions'])
max_mutations_cistrans = int(p_dict['max_mutations_cistrans'])
max_mutations_torsions = int(p_dict['max_mutations_torsions'])
aims_call = str(p_dict['aims_call'])
iter_limit_conv = int(p_dict['iter_limit_conv'])
energy_diff_conv = float(p_dict['energy_diff_conv'])
energy_wanted = float(p_dict['energy_wanted'])

cnt_max = 100
array = np.array
population, blacklist = [], []
min_energy = []
print_output(" \n ___Restart will be performed___")
with open("backup_mol.dat", 'r') as inf:
    mol = eval(inf.readline())
inf.close()
with open("backup_population.dat", 'r') as inf:
    for line in inf:
        population.append(eval(line))
inf.close()
with open("backup_blacklist.dat", 'r') as inf:
    for line in inf:
        blacklist.append(eval(line))
inf.close()
with open("backup_min_energy.dat", 'r') as inf:
    for line in inf:
        min_energy.append(eval(line))
inf.close()