コード例 #1
0
ファイル: ga.py プロジェクト: adrianasupady/fafoom
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.")
コード例 #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.")
コード例 #3
0
    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.")
            cnt += 1
            continue
        if str3d not in blacklist:
            name = "initial_%d" % (len(population))
            # Perform the local optimization
            run_util.optimize(str3d, energy_function, params, name)
            run_util.check_for_kill()
            str3d.send_to_blacklist(blacklist)
            population.append(str3d)
            print_output(
                str(str3d) + ", energy: " + str(float(str3d)) +
                ", was added to the population")
            run_util.relax_info(str3d)
            cnt += 1
        else:
            print_output("Geomerty of " + str(str3d) + " is fine, but already "
                         "known.")
            cnt += 1
    if cnt == cnt_max:
        print_output("The allowed number of trials for building the "
                     "population has been exceeded. The code terminates.")
コード例 #4
0
ファイル: ga.py プロジェクト: adrianasupady/fafoom
    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.")
            cnt += 1
            continue
        if str3d not in blacklist:
            name = "initial_%d" % (len(population))
            # Perform the local optimization
            run_util.optimize(str3d, energy_function, params, name)
            run_util.check_for_kill()
            str3d.send_to_blacklist(blacklist)
            population.append(str3d)
            print_output(str(str3d)+", energy: "+str(float(str3d)) +
                         ", was added to the population")
            run_util.relax_info(str3d)
            cnt += 1
        else:
            print_output("Geomerty of "+str(str3d)+" is fine, but already "
                         "known.")
            cnt += 1
    if cnt == cnt_max:
        print_output("The allowed number of trials for building the "
                     "population has been exceeded. The code terminates.")
        sys.exit(0)