Skip to content

Commit

Permalink
Merge pull request #3 from jjmaldonis/master
Browse files Browse the repository at this point in the history
started adding pieces of the functionality
  • Loading branch information
jjmaldonis committed May 5, 2016
2 parents 4360224 + 29b8564 commit ae9ab06
Show file tree
Hide file tree
Showing 39 changed files with 1,403 additions and 71 deletions.
9 changes: 5 additions & 4 deletions examples/Au18/structopt.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
},
"mutations": {
"options": [
"lattice_alteration",
"lattice_alteration_group",
"rotation_geo",
"rotation"
"move_atoms",
"swap_positions",
"swap_species",
"rotate_atoms",
"rotate_cluster"
]
},
"fingerprinters": {
Expand Down
96 changes: 96 additions & 0 deletions examples/Au18/structopt_load_xyz.in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"globals":
{
"USE_MPI4PY": true
},
"generators": {
"structure_type": "cluster",
"initializers": [
{
"number_of_individuals": 5,
"data": {
"filenames": [
"/home/jmaldonis/StructOpt_modular/examples/Au18/structure1.xyz",
"/home/jmaldonis/StructOpt_modular/examples/Au18/structure2.xyz",
"/home/jmaldonis/StructOpt_modular/examples/Au18/structure3.xyz",
"/home/jmaldonis/StructOpt_modular/examples/Au18/structure4.xyz",
"/home/jmaldonis/StructOpt_modular/examples/Au18/structure5.xyz"
]
}
}
]
},
"fitnesses":
{
"modules": [
"LAMMPS",
"FEMSIM"
],
"weights": [
1.0,
1.0
],
"FEMSIM": {
"parameter_filename": "/home/maldonis/USIT/StructOpt/StructOpt/fitness/FEMSIM/femsim-hrmc/parameters/femsim.in",
"vk_data_filename": "/home/maldonis/USIT/StructOpt/StructOpt/fitness/FEMSIM/femsim-hrmc/data/fem_exp_Zr50Cu35Al15_t3.txt",
"xsize": 28.2842712474619,
"ysize": 28.2842712474619,
"zsize": 28.2842712474619,
"Q": 0.0305,
"nphi": 1,
"npsi": 40,
"ntheta": 20,
"thickness_scaling_factor": 28.6378
},
"LAMMPS":{
"keep_files": true,
"min_style": "cg\nmin_modify line quadratic",
"minimize": "1e-8 1e-8 5000 10000",
"pair_style": "eam",
"parallel": true,
"potential_file": "/home/jmaldonis/StructOpt/examples/Au18/Au_u3.eam",
"thermo_steps": 1000
}
},
"relaxations":
{
"modules": [
"LAMMPS"
],
"LAMMPS":{
"keep_files": true,
"min_style": "cg\nmin_modify line quadratic",
"minimize": "1e-8 1e-8 5000 10000",
"pair_style": "eam",
"parallel": true,
"potential_file": "/home/jmaldonis/StructOpt/examples/Au18/Au_u3.eam",
"thermo_steps": 1000
}
},
"mutations": {
"options": [
"move_atoms",
"swap_positions",
"swap_species",
"rotate_atoms",
"rotate_cluster"
]
},
"fingerprinters": {
"options": []
},

"crossovers": {
"options": ["do_nothing"]
},
"predators": {
"options": ["do_nothing"]
},
"selections": {
"options": ["do_nothing"]
},

"fileio": {},
"postprocessing": {},
"tools": {}
}
6 changes: 6 additions & 0 deletions examples/Au18/structure1.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
4
10.0 10.0 10.0
Zr 1.0 1.0 1.0
Zr 2.0 2.0 2.0
Zr 3.0 3.0 3.0
Zr 4.0 4.0 4.0
6 changes: 6 additions & 0 deletions examples/Au18/structure2.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
4
10.0 10.0 10.0
Zr 1.0 1.0 1.0
Zr 2.0 2.0 2.0
Zr 3.0 3.0 3.0
Zr 4.0 4.0 4.0
6 changes: 6 additions & 0 deletions examples/Au18/structure3.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
4
10.0 10.0 10.0
Zr 1.0 1.0 1.0
Zr 2.0 2.0 2.0
Zr 3.0 3.0 3.0
Zr 4.0 4.0 4.0
6 changes: 6 additions & 0 deletions examples/Au18/structure4.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
4
10.0 10.0 10.0
Zr 1.0 1.0 1.0
Zr 2.0 2.0 2.0
Zr 3.0 3.0 3.0
Zr 4.0 4.0 4.0
6 changes: 6 additions & 0 deletions examples/Au18/structure5.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
4
10.0 10.0 10.0
Zr 1.0 1.0 1.0
Zr 2.0 2.0 2.0
Zr 3.0 3.0 3.0
Zr 4.0 4.0 4.0
7 changes: 6 additions & 1 deletion structopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import time
import logging
import os

from . import fileio
from optimizer import Optimizer
from .optimizer import Optimizer
from . import common

def setup(parameter_file):
parameters = fileio.parameters.read(parameter_file)
Expand Down Expand Up @@ -40,6 +42,9 @@ def setup(parameter_file):
if logging_level <= logging.DEBUG:
debug_logger = fileio.logger_utils.initialize_logger(filename='{}-by-rank-debug.log'.format(parameters.globals.loggername), name="by-rank-debug", level=logging_level)

if not os.path.exists(parameters.globals.output_filename):
os.mkdir(parameters.globals.output_filename)

# Set defaults for parameters and globally scope them
parameters = fileio.parameters.set_default(parameters)
globals()["parameters"] = parameters
Expand Down
57 changes: 57 additions & 0 deletions structopt/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
rm cluster/*.pyc
rm cluster/individual/*.pyc
rm cluster/population/*.pyc
rm common/*.pyc
rm common/individual/*.pyc
rm common/individual/fingerprinters/*.pyc
rm common/individual/fitnesses/*.pyc
rm common/individual/generators/*.pyc
rm common/individual/mutations/*.pyc
rm common/individual/relaxations/*.pyc
rm common/population/*.pyc
rm common/population/crossovers/*.pyc
rm common/population/fitnesses/*.pyc
rm common/population/predators/*.pyc
rm common/population/relaxations/*.pyc
rm common/population/selections/*.pyc
rm crystal/*.pyc
rm crystal/individual/*.pyc
rm crystal/population/*.pyc
rm defect/*.pyc
rm defect/individual/*.pyc
rm defect/population/*.pyc
rm fileio/*.pyc
rm postprocessing/*.pyc
rm surface/*.pyc
rm surface/individual/*.pyc
rm surface/population/*.pyc
rm tools/*.pyc

rm -rf cluster/__pycache__
rm -rf cluster/individual/pycache__
rm -rf cluster/population/pycache__
rm -rf common/pycache__
rm -rf common/individual/pycache__
rm -rf common/individual/fingerprinters/pycache__
rm -rf common/individual/fitnesses/pycache__
rm -rf common/individual/generators/pycache__
rm -rf common/individual/mutations/pycache__
rm -rf common/individual/relaxations/pycache__
rm -rf common/population/pycache__
rm -rf common/population/crossovers/pycache__
rm -rf common/population/fitnesses/pycache__
rm -rf common/population/predators/pycache__
rm -rf common/population/relaxations/pycache__
rm -rf common/population/selections/pycache__
rm -rf crystal/pycache__
rm -rf crystal/individual/pycache__
rm -rf crystal/population/pycache__
rm -rf defect/pycache__
rm -rf defect/individual/pycache__
rm -rf defect/population/pycache__
rm -rf fileio/pycache__
rm -rf postprocessing/pycache__
rm -rf surface/pycache__
rm -rf surface/individual/pycache__
rm -rf surface/population/pycache__
rm -rf tools/pycache__
4 changes: 3 additions & 1 deletion structopt/cluster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@


class Cluster(Individual):
"""A stucture containing a cluster of atoms."""
""" A stucture containing a non-periodic cluster of atoms. Relaxation algorithms such as LAMMPS and VASP require
a periodic structure, so when run though these types of algorithms, the cluster is embedded in a larger box.
"""

1 change: 1 addition & 0 deletions structopt/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import individual, population
29 changes: 26 additions & 3 deletions structopt/common/individual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
import random
import ase
from importlib import import_module
import numpy as np

import structopt
from . import relaxations, fitnesses, mutations, fingerprinters, mutations


class Individual(ase.Atoms):
"""An abstract base class for a structure."""

def __init__(self, **kwargs):
def __init__(self, index=None, **kwargs):
self._kwargs = kwargs # Store the parameters necessary for initializing for making a copy of self
self.index = index

cls_name = self.__class__.__name__.lower()
# Load in the appropriate functionality
fingerprinters = import_module('structopt.{cls_name}.individual.fingerprinters'.format(cls_name=cls_name))
Expand All @@ -23,22 +28,40 @@ def __init__(self, **kwargs):
self.relaxations = relaxations.Relaxations()

# Initialize the ase.Atoms structure
super().__init__()
generators = import_module('structopt.{cls_name}.individual.generators'.format(cls_name=cls_name))
generators.generate(self, **kwargs)


def mutate(self):
self.mutations.select_mutation()
return self.mutations.mutate(self)


def relax(self):
return self.relaxations.relax(self)


def fitness(self):
return self.fitnesses.fitness(self)


def fingerprint(self):
return self.fingerprinters.fingerprint(self)

def __repr__(self):
return "<{cls} object at {loc}>".format(cls=self.__class__.__name__, loc=hex(id(self)))

def get_atom_indices_within_distance_of_atom(self, atom_index, distance):
dists = self.get_distances(atom_index, slice(None, None, None))
return np.where(dists < distance)

def get_nearest_atom_indices(self, atom_index, count):
dists = self.get_distances(atom_index, slice(None, None, None))[0]
return np.argsort(dists)[:count]

def copy(self):
new = self.__class__()
new.index = self.index # TODO
new.extend(self)
return new


32 changes: 29 additions & 3 deletions structopt/common/individual/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import functools
import numpy as np

import structopt
from structopt.common.individual import Individual
from .read_xyz import read_xyz


def generate(individual, *args, **kwargs):
def generate(individual, **kwargs):
""" Uses the relevant parameters from structopt to intialize the input Individual by modifying it in-place.
Args:
individual (Individual): an Individual that is uninitialized
*args, **kwargs: arguments for either ase.Atoms or a different generator function
**kwargs: keyword arguments for either ase.Atoms or a different generator function
"""
if 'filenames' in kwargs:
filename = kwargs['filenames'][individual.index]
atoms = read_xyz(filename)
individual.extend(atoms)
#individual.set_atomic_numbers(atoms.get_atomic_numbers())
#individual.set_charges(atoms.get_charges())
#individual.set_chemical_symbols(atoms.get_chemical_symbols())
#individual.set_initial_magnetic_moments(atoms.get_initial_magnetic_moments())
#individual.set_masses(atoms.get_masses())
#individual.set_momenta(atoms.get_momenta())
#individual.set_positions(atoms.get_positions())
#individual.set_scaled_positions(atoms.get_scaled_positions())
#individual.set_tags(atoms.get_tags())
#individual.set_velocities(atoms.get_velocities())

individual.set_pbc(True)
with open(filename) as of:
of.readline() # number of atoms
sizes = of.readline() # comment == box size
sizes = sizes.split()[:3]
sizes = [float(x) for x in sizes]
cell = np.identity(3)
np.fill_diagonal(cell, sizes)
individual.set_cell(cell)

return None

4 changes: 4 additions & 0 deletions structopt/common/individual/generators/read_xyz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import structopt.fileio

def read_xyz(filename):
return structopt.fileio.read_xyz(filename)
Loading

0 comments on commit ae9ab06

Please sign in to comment.