Skip to content

Commit

Permalink
Merge pull request #17 from pyscal/improve_gb
Browse files Browse the repository at this point in the history
Improve gb
  • Loading branch information
srmnitc authored Sep 19, 2023
2 parents cf1d2ec + 31cb93f commit 644191a
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 125 deletions.
4 changes: 2 additions & 2 deletions src/pyscal3/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ def _generate_bool_list(self, ids=None, indices=None, condition=None, selection=
non_nones = sum(x is not None for x in [ids, indices, condition])
if non_nones > 1:
raise ValueError("Only one of ids, indices or condition should be provided")
elif ((non_nones == 0) and (selection==False)):
warnings.warn("No conditions provided, all atoms will be included")
#elif ((non_nones == 0) and (selection==False)):
# warnings.warn("No conditions provided, all atoms will be included")
#generate a list of indices
if selection:
indices = [x for x in range(self.nreal) if self["condition"][x]]
Expand Down
38 changes: 37 additions & 1 deletion src/pyscal3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pyscal3.traj_process as ptp
from pyscal3.formats.ase import convert_snap
import pyscal3.structure_creator as pcs
from pyscal3.grain_boundary import GrainBoundary

import pyscal3.operations.operations as operations
import pyscal3.operations.cna as cna
Expand All @@ -33,6 +34,7 @@
import pyscal3.operations.voronoi as voronoi
import pyscal3.operations.chemical as chemical
import pyscal3.operations.visualize as visualize

#import pyscal.routines as routines
#import pyscal.visualization as pv

Expand Down Expand Up @@ -86,7 +88,38 @@ def _make_general_lattice(positions,
s.atoms._lattice = 'custom'
s.atoms._lattice_constant = lattice_constant
s._structure_dict = sdict
return s
return s

def _make_grain_boundary(axis,
sigma, gb_plane,
structure = None,
element = None,
lattice_constant = 1,
repetitions = (1,1,1),
overlap=0.0):

gb = GrainBoundary()
gb.create_grain_boundary(axis=axis, sigma=sigma,
gb_plane=gb_plane)

if structure is not None:
atoms, box, sdict = gb.populate_grain_boundary(structure,
repetitions = repetitions,
lattice_parameter = lattice_constant,
overlap=overlap)
elif element is not None:
atoms, box, sdict = gb.populate_grain_boundary(element,
repetitions=repetitions,
overlap=overlap)
s = System()
s.box = box
s.atoms = atoms
s.atoms._lattice = structure
s.atoms._lattice_constant = lattice_constant
s._structure_dict = sdict
#s = operations.remap_to_box(s)
return s


class System:
"""
Expand All @@ -108,6 +141,9 @@ class System:
element_dict[key]['structure'],
lattice_constant=element_dict[key]['lattice_constant'],
element = key), pcs.make_crystal)

mapdict["grain_boundary"] = _make_grain_boundary

create._add_attribute(mapdict)

def __init__(self, filename=None, format="lammps-dump",
Expand Down
11 changes: 10 additions & 1 deletion src/pyscal3/csl.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ def generate_bicrystal_atoms(ortho1, ortho2, basis):
atoms2 = dot(rot2, atoms2.T).T

atoms2[:, 0] = atoms2[:, 0] - norm(Or_2[0, :]) # - tol
#mincord = min(atoms2[:,0])
#shift it back
#atoms2[:, 0] = atoms2[:, 0] - mincord
return atoms1, atoms2


Expand Down Expand Up @@ -602,12 +605,18 @@ def populate_gb(ortho1, ortho2, basis,
dimx, dimy, dimz = dim

#get box bounds
xlo = -1 * np.round(norm(ortho1[:, 0]) * dimx * lattice_parameter, 8)
xlo = -1*np.round(norm(ortho1[:, 0]) * dimx * lattice_parameter, 8)
xhi = np.round(norm(ortho1[:, 0]) * dimx * lattice_parameter, 8)
LenX = xhi - xlo

#shift atoms
atoms1[:,0] = atoms1[:,0] - xlo
atoms2[:,0] = atoms2[:,0] - xlo

ylo = 0.0
yhi = np.round(norm(ortho1[:, 1]) * dimy * lattice_parameter, 8)
LenY = yhi - ylo

zlo = 0.0
zhi = np.round(norm(ortho1[:, 2]) * dimz * lattice_parameter, 8)
LenZ = zhi - zlo
Expand Down
51 changes: 32 additions & 19 deletions src/pyscal3/grain_boundary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import numpy as np
import os
import pyscal3.csl as csl
import pyscal3.crystal_structures as pcs
from pyscal3.core import System, Atoms
from pyscal3.core import Atoms
from pyscal3.attributes import read_yaml

structure_dict = read_yaml(os.path.join(os.path.dirname(__file__), "data/structure_data.yaml"))
element_dict = read_yaml(os.path.join(os.path.dirname(__file__), "data/element_data.yaml"))

class GrainBoundary:
def __init__(self):
Expand Down Expand Up @@ -92,36 +95,46 @@ def create_grain_boundary(self, axis,
raise TypeError("GB cannot be created with the given input!")
return valid

def populate_grain_boundary(self, lattice, element=None, repetitions=(1,1,1), lattice_parameter=1, overlap=0.0):
if lattice in pcs.structures.keys():
def populate_grain_boundary(self, lattice, element=None,
repetitions=(1,1,1), lattice_parameter=1, overlap=0.0):
if lattice in structure_dict.keys():
structure = lattice
element = element
basis = pcs.structures[lattice]['positions']
sdict = pcs.structures[lattice]
elif lattice in pcs.elements.keys():
structure = pcs.elements[lattice]['structure']
if 'conventional' not in structure_dict[lattice].keys():
raise ValueError("GBs can only be filled with conventional lattice, choose another structure")
basis = structure_dict[lattice]['conventional']['positions']
sdict = structure_dict[lattice]['conventional']

elif lattice in element_dict.keys():
structure = element_dict[lattice]['structure']
element = lattice
lattice_parameter = pcs.elements[lattice]['lattice_constant']
basis = pcs.structures[structure]['positions']
sdict = pcs.structures[structure]
if 'conventional' not in structure_dict[structure].keys():
raise ValueError("GBs can only be filled with conventional lattice, choose another structure")
lattice_parameter = element_dict[element]['lattice_constant']
basis = structure_dict[structure]['conventional']['positions']
sdict = structure_dict[structure]['conventional']
else:
raise ValueError("Unknown lattice type")

box, atoms1, atoms2 = csl.populate_gb(self._ortho_1, self._ortho_2,
np.array(basis),
lattice_parameter,
dim=repetitions,
overlap=overlap)

atoms = Atoms()
total_atoms = np.concatenate((atoms1, atoms2))
if element is not None:
atoms.from_dict({"positions": total_atoms, "species": [element for x in range(len(total_atoms))]})
else:
atoms.from_dict({"positions": total_atoms})
sys = System()
sys.box = box
sys.atoms = atoms
sys.atoms._lattice = structure
sys.atoms._lattice_constant = lattice_parameter
sys._structure_dict = sdict
sys.remap_atoms_into_box()
return sys

return atoms, box, sdict
#sys = System()
#sys.box = box
#sys.atoms = atoms
#sys.atoms._lattice = structure
#sys.atoms._lattice_constant = lattice_parameter
#sys._structure_dict = sdict
#sys.remap_atoms_into_box()
#return sys
13 changes: 7 additions & 6 deletions src/pyscal3/operations/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,15 @@ def remap_to_box(system):
-------
system
"""
rot = np.array(system.box).T
rotinv = np.linalg.inv(rot)
#rot = np.array(system._box).T
#rotinv = np.linalg.inv(rot)

for x in range(system.natoms):
for x in range(system.atoms.ntotal):
pos = pc.remap_atom_into_box(system.atoms["positions"][x],
system.triclinic,
rot,
rotinv,
system.box_dimensions)
system.rot,
system.rotinv,
system.boxdims)
#print(f'{system.atoms["positions"][x]} changed to {pos} ')
system.atoms["positions"][x] = pos
return system
Loading

0 comments on commit 644191a

Please sign in to comment.