Commit 5970e00a authored by Carl Poelking's avatar Carl Poelking
Browse files

Spawning criterion.

parent fa88b59e
......@@ -25,14 +25,10 @@ logging.basicConfig(
select_struct_label = 'config.xyz'
exclude_centers = []
adaptor_type = 'global-generic'
kernel_type = 'dot' # 'dot-harmonic'
alpha = +1.
mu = 0.9
sc = 0.1 # 1.5 # 0.1
average_energy = True
lj_sigma = 0.02 # 0.00001 # 0.02
kernel_type = 'dot'
sc = 0.1
lj_sigma = 0.02
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# NOTE adaptor_type = 'generic' => exclude center if not constrained in optimization
# OPTIONS
options = soap.Options()
......@@ -40,10 +36,8 @@ options.excludeCenters(['H'])
options.excludeTargets(['H'])
options.excludeCenterIds(exclude_centers)
options.excludeTargetIds([])
# Spectrum
options.set('spectrum.gradients', True)
options.set('spectrum.2l1_norm', False) # <- pull here (True/False)
# Basis
options.set('radialbasis.type', 'gaussian')
options.set('radialbasis.mode', 'adaptive')
options.set('radialbasis.N', 9)
......@@ -55,31 +49,14 @@ options.set('radialcutoff.type', 'heaviside')
options.set('radialcutoff.center_weight', 0.5)
options.set('angularbasis.type', 'spherical-harmonic')
options.set('angularbasis.L', 6)
# Kernel
options.set('kernel.adaptor', adaptor_type) # <- pull here (generic/global-generic)
options.set('kernel.type', kernel_type)
options.set('kernel.delta', 1.)
options.set('kernel.xi', 2.) # <- pull here (1., ..., 4., ...)
options.set('kernel.mu', mu)
# Cube files
options.set('densitygrid.N', 20)
options.set('densitygrid.dx', 0.15)
# LOAD STRUCTURES
structures = [
soap.tools.setup_structure_ase(c.config_file, c.atoms)
for c in soap.tools.ase_load_all('in.configs')
]
struct_dict = {}
for struct in structures:
print struct.label
struct_dict[struct.label] = struct
# SELECT STRUCTURE
struct = struct_dict[select_struct_label]
# DEFINE INTERACTION TEMPLATES
"""
pot_options_dot = soap.Options()
pot_options_dot.set('kernel.adaptor', 'global-generic')
pot_options_dot.set('kernel.type', 'dot')
......@@ -87,6 +64,7 @@ pot_options_dot.set('kernel.alpha', -1.)
pot_options_dot.set('kernel.delta', 1.)
pot_options_dot.set('kernel.xi', 2.)
pot_options_dot.set('kernel.mu', 0.5)
pot_options_harm = soap.Options()
pot_options_harm.set('kernel.adaptor', 'global-generic')
pot_options_harm.set('kernel.type', 'dot-harmonic')
......@@ -94,16 +72,33 @@ pot_options_harm.set('kernel.alpha', +1.)
pot_options_harm.set('kernel.delta', 1.)
pot_options_harm.set('kernel.xi', 2.)
pot_options_harm.set('kernel.mu', 0.5)
pot_options_lj = soap.Options()
pot_options_lj.set('potentials.lj.sigma', 0.02)
"""
pot_options_dotlj = soap.Options()
pot_options_dotlj.set('kernel.adaptor', 'global-generic')
pot_options_dotlj.set('kernel.type', 'dot-lj')
pot_options_dotlj.set('kernel.alpha', +1.)
pot_options_dotlj.set('kernel.delta', 1.)
pot_options_dotlj.set('kernel.xi', 2.)
pot_options_dotlj.set('kernel.lj_sigma', 0.125) # 0.1 # 0.2 too large => TODO Better force capping required
pot_options_dotlj.set('kernel.lj_eps_cap', 0.001)
# LOAD STRUCTURES
structures = [
soap.tools.setup_structure_ase(c.config_file, c.atoms)
for c in soap.tools.ase_load_all('in.configs')
]
struct_dict = {}
for struct in structures:
print struct.label
struct_dict[struct.label] = struct
# SELECT STRUCTURE
struct = struct_dict[select_struct_label]
# CREATE TREE
osio.cd('out.files')
tree = SimSpaceTree(options)
tree.seed(struct)
......@@ -113,22 +108,19 @@ N_spawn = [3,3]
N_generations = 4
N_spawn = [2,2,2,2]
pot_options_dotlj = soap.Options()
pot_options_dotlj.set('kernel.adaptor', 'global-generic')
pot_options_dotlj.set('kernel.type', 'dot-lj')
pot_options_dotlj.set('kernel.alpha', +1.)
pot_options_dotlj.set('kernel.delta', 1.)
pot_options_dotlj.set('kernel.xi', 2.)
pot_options_dotlj.set('kernel.lj_sigma', 0.1) # 0.2
pot_options_dotlj.set('kernel.lj_eps_cap', 0.001)
N_generations = 9
N_spawn = [ 2 for n in range(N_generations) ]
authorize_spawn_fct = lambda joint: joint.node.energy <= 0.0
for n in range(N_generations):
gen_id = n+1
gen_prefix = 'out.gen_%d' % gen_id
print "Spawn generation %d" % gen_id
new_joints = tree.spawn(N_spawn[n])
tree.summarize()
tree.top.computePotentialEnergy()
new_joints = tree.spawn(N_spawn[n], authorize_spawn_fct)
tree.summarize()
tree.writeParentChildPairs('%s.tree.txt' % gen_prefix)
# POTENTIALS
......@@ -147,7 +139,7 @@ for n in range(N_generations):
# OUTPUT
tree.top.writeData(prefix=gen_prefix)
raw_input('...')
#raw_input('...')
osio.root()
......
......@@ -102,7 +102,7 @@ class SimSpaceNode(object):
del self.potentials_self
self.potentials = []
self.potentials_self = []
def evaluatePotentialEnergy(self):
def computePotentialEnergy(self):
self.energy = 0.
for pot in self.potentials:
self.energy += pot.computeEnergy()
......@@ -138,7 +138,7 @@ class SimSpaceTopology(object):
def computePotentialEnergy(self):
self.energy = 0.
for node in self.nodes:
self.energy += node.computeEnergy()
self.energy += node.computePotentialEnergy()
return self.energy
def createNode(self, structure):
node_id = len(self.nodes)+1
......@@ -163,6 +163,9 @@ class SimSpaceTopology(object):
# Kernel
K = self.computeKernelMatrix()
np.savetxt('%s.kernelmatrix.txt' % prefix, K)
# Energy
E = [ node.computePotentialEnergy() for node in self.nodes ]
np.savetxt('%s.energy.txt' % prefix, E)
return
class SimSpacePotential(object):
......@@ -223,16 +226,17 @@ class SimSpaceJoint(object):
self.child_joints = []
def hasChildren(self):
return len(self.child_joints) > 0
def spawn(self, n):
def spawn(self, n, authorize_spawn_fct):
new_joints = []
if self.hasChildren():
for child_joint in self.child_joints:
new_joints = new_joints + child_joint.spawn(n)
new_joints = new_joints + child_joint.spawn(n, authorize_spawn_fct)
else:
for i in range(n):
child_joint = SimSpaceJoint(self.top, self)
self.child_joints.append(child_joint)
new_joints.append(child_joint)
if authorize_spawn_fct(self):
for i in range(n):
child_joint = SimSpaceJoint(self.top, self)
self.child_joints.append(child_joint)
new_joints.append(child_joint)
return new_joints
def summarize(self, indent=''):
print '%sID=%d: %d children' % (indent, self.node.id, len(self.child_joints))
......@@ -256,8 +260,8 @@ class SimSpaceTree(object):
self.joints.append(self.root_joint)
self.generations.append([self.root_joint])
return self.root_joint
def spawn(self, n):
new_joints = self.root_joint.spawn(n)
def spawn(self, n, authorize_spawn_fct=lambda node: True):
new_joints = self.root_joint.spawn(n, authorize_spawn_fct)
self.joints = self.joints + new_joints
self.generations.append(new_joints)
return new_joints
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment