From 2c3982dcb9a13b7830f931d22eec89244fd13553 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Mon, 18 Sep 2023 22:07:16 +0200 Subject: [PATCH 1/6] update GB code --- src/pyscal3/grain_boundary.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pyscal3/grain_boundary.py b/src/pyscal3/grain_boundary.py index cd0e2be..31ce656 100644 --- a/src/pyscal3/grain_boundary.py +++ b/src/pyscal3/grain_boundary.py @@ -92,31 +92,40 @@ 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): + def populate_grain_boundary(self, lattice, element=None, + repetitions=(1,1,1), lattice_parameter=1, overlap=0.0): if lattice in pcs.structures.keys(): structure = lattice element = element - basis = pcs.structures[lattice]['positions'] - sdict = pcs.structures[lattice] + if 'conventional' not in pcs.structures[lattice].keys(): + raise ValueError("GBs can only be filled with conventional lattice, choose another structure") + basis = pcs.structures[lattice]['conventional']['positions'] + sdict = pcs.structures[lattice]['conventional'] + elif lattice in pcs.elements.keys(): structure = pcs.elements[lattice]['structure'] element = lattice - lattice_parameter = pcs.elements[lattice]['lattice_constant'] - basis = pcs.structures[structure]['positions'] - sdict = pcs.structures[structure] + if 'conventional' not in pcs.structures[lattice].keys(): + raise ValueError("GBs can only be filled with conventional lattice, choose another structure") + lattice_parameter = pcs.elements[lattice]['conventional']['lattice_constant'] + basis = pcs.structures[structure]['conventional']['positions'] + sdict = pcs.structures[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 From 4bc90eb9eaeaaa18d8bab83d0a7f9a52cf0487eb Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Tue, 19 Sep 2023 09:02:35 +0200 Subject: [PATCH 2/6] fix gb and add plot --- src/pyscal3/core.py | 38 ++++- src/pyscal3/grain_boundary.py | 44 ++--- src/pyscal3/operations/visualize.py | 241 ++++++++++++++++++++-------- 3 files changed, 236 insertions(+), 87 deletions(-) diff --git a/src/pyscal3/core.py b/src/pyscal3/core.py index a5d3d6e..cd6ca6d 100644 --- a/src/pyscal3/core.py +++ b/src/pyscal3/core.py @@ -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 @@ -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 @@ -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: """ @@ -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", diff --git a/src/pyscal3/grain_boundary.py b/src/pyscal3/grain_boundary.py index 31ce656..32481fe 100644 --- a/src/pyscal3/grain_boundary.py +++ b/src/pyscal3/grain_boundary.py @@ -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): @@ -94,22 +97,22 @@ def create_grain_boundary(self, axis, def populate_grain_boundary(self, lattice, element=None, repetitions=(1,1,1), lattice_parameter=1, overlap=0.0): - if lattice in pcs.structures.keys(): + if lattice in structure_dict.keys(): structure = lattice element = element - if 'conventional' not in pcs.structures[lattice].keys(): + if 'conventional' not in structure_dict[lattice].keys(): raise ValueError("GBs can only be filled with conventional lattice, choose another structure") - basis = pcs.structures[lattice]['conventional']['positions'] - sdict = pcs.structures[lattice]['conventional'] + basis = structure_dict[lattice]['conventional']['positions'] + sdict = structure_dict[lattice]['conventional'] - elif lattice in pcs.elements.keys(): - structure = pcs.elements[lattice]['structure'] + elif lattice in element_dict.keys(): + structure = element_dict[lattice]['structure'] element = lattice - if 'conventional' not in pcs.structures[lattice].keys(): + if 'conventional' not in structure_dict[structure].keys(): raise ValueError("GBs can only be filled with conventional lattice, choose another structure") - lattice_parameter = pcs.elements[lattice]['conventional']['lattice_constant'] - basis = pcs.structures[structure]['conventional']['positions'] - sdict = pcs.structures[structure]['conventional'] + lattice_parameter = element_dict[element]['lattice_constant'] + basis = structure_dict[structure]['conventional']['positions'] + sdict = structure_dict[structure]['conventional'] else: raise ValueError("Unknown lattice type") @@ -126,11 +129,12 @@ def populate_grain_boundary(self, lattice, element=None, 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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/src/pyscal3/operations/visualize.py b/src/pyscal3/operations/visualize.py index eb05eef..6cadebe 100644 --- a/src/pyscal3/operations/visualize.py +++ b/src/pyscal3/operations/visualize.py @@ -4,50 +4,136 @@ import matplotlib.pyplot as plt import matplotlib -def plot_by_selection(sys, height=500, width=500, size=5, ): +def create_box_plot(box, origin=[0,0,0]): + """ + Create traces which correspond to the simulation cell + + Parameters + ---------- + box : list + dimensions of the simulation box + + origin : list, optional + Origin of the simulation box. Default [0, 0, 0] + + Returns + ------- + traces : list of Scatter3d objects + + """ try: - import ipyvolume as ipv + from plotly import graph_objs as go + import ipywidgets as widgets except ImportError: print("Install ipyvolume for visualisation") + box = np.array(box) + origin = np.array(origin) + combos = list(itertools.combinations(range(3), 2)) + faces = [] + for combo in combos: + f1 = [origin, box[combo[0]], box[combo[0]]+box[combo[1]], box[combo[1]], origin] + s = combo[0] + combo[1] + t = 3-s + f2 = [origin + box[t], box[combo[0]]+ box[t], box[combo[0]]+box[combo[1]]+ box[t], box[combo[1]]+ box[t], origin + box[t]] + faces.append(np.array(f1)) + faces.append(np.array(f2)) + traces = [] + for face in faces: + trace = go.Scatter3d( + x=face[:,0], + y=face[:,1], + z=face[:,2], + mode='lines', + name='lines', + line=dict(width=2.0, color='#263238'), + showlegend=False + ) + traces.append(trace) + return traces + +def plot_by_selection(sys, radius=10, + opacity=1.0): + + try: + from plotly import graph_objs as go + except ImportError: + print("Install plotly for visualisation") + cFalse = '#b0bec5' cTrue = '#ef5350' - scatter = ipv.scatter(sys.atoms.positions[:,0][sys.atoms.selection], - sys.atoms.positions[:,1][sys.atoms.selection], - sys.atoms.positions[:,2][sys.atoms.selection], - marker='sphere', - size=size, - lighting=True, - color=cTrue) - - scatter = ipv.scatter(sys.atoms.positions[:,0][np.logical_not(sys.atoms.selection)], - sys.atoms.positions[:,1][np.logical_not(sys.atoms.selection)], - sys.atoms.positions[:,2][np.logical_not(sys.atoms.selection)], - marker='sphere', - size=size, - lighting=True, - color=cFalse) - #plotting box box = sys.box.copy() origin = np.array([0,0,0]) - combos = list(itertools.combinations(range(3), 2)) - for combo in combos: - f1 = [origin, box[combo[0]], box[combo[0]]+box[combo[1]], box[combo[1]], origin] - s = combo[0] + combo[1] - t = 3-s - f2 = [origin + box[t], box[combo[0]]+ box[t], box[combo[0]]+box[combo[1]]+ box[t], box[combo[1]]+ box[t], origin + box[t]] - unn = np.vstack((f1, f2)) - ipv.plot(unn[:,0], unn[:,1], unn[:,2], color='#546e7a') - - ipv.style.box_off() - ipv.style.axes_off() - ipv.squarelim() - - #done - return ipv.gcf() + traces = create_box_plot(box, origin) + + data=go.Scatter3d( + x=sys.atoms.positions[:,0][sys.atoms.selection], + y=sys.atoms.positions[:,1][sys.atoms.selection], + z=sys.atoms.positions[:,2][sys.atoms.selection], + mode='markers', + opacity=1.0, + marker=dict( + sizemode='diameter', + sizeref=750, + size=radius, + color = cTrue, + opacity = opacity, + #colorscale = colorscale, + #colorbar=dict(thickness=20, title=cmap_title), + line=dict(width=0.5, color='#455A64'), + ) + ) + + traces.append(data) + + data=go.Scatter3d( + x=sys.atoms.positions[:,0][np.logical_not(sys.atoms.selection)], + y=sys.atoms.positions[:,1][np.logical_not(sys.atoms.selection)], + z=sys.atoms.positions[:,2][np.logical_not(sys.atoms.selection)], + mode='markers', + opacity=1.0, + marker=dict( + sizemode='diameter', + sizeref=750, + size=radius, + color = cFalse, + opacity = opacity, + #colorscale = colorscale, + #colorbar=dict(thickness=20, title=cmap_title), + line=dict(width=0.5, color='#455A64') + ) + ) + + traces.append(data) + + fig = go.Figure(data=traces) + fig.update_layout(scene = dict( + xaxis_title="", + yaxis_title="", + zaxis_title="", + xaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",), + yaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64"), + zaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",),), + width=700, + margin=dict( + r=10, l=10, + b=10, t=10) + ) + fig.update_layout(showlegend=False) + fig.show() + def plot_by_property(sys, colorby, ids=None, indices=None, @@ -57,49 +143,72 @@ def plot_by_property(sys, colorby, ids=None, try: - import ipyvolume as ipv + from plotly import graph_objs as go except ImportError: - print("Install ipyvolume for visualisation") + print("Install plotly for visualisation") colorby = colorby.copy().astype(int) sys.apply_selection(ids=ids, indices=indices, condition=condition) colorby = [x for count, x in enumerate(colorby) if sys.atoms.selection[count]] + + colorby = colorby.copy() + a = min(colorby) + b = max(colorby) + prop = (colorby - a)/(b - a) - fig = ipv.figure(debug=False, width=width, height=height) - - prop = (colorby.copy() - min(colorby))/(max(colorby) - min(colorby)) - cmap = matplotlib.cm.get_cmap(cmap) - colors = [cmap(x) for x in prop] - - scatter = ipv.scatter(sys.atoms.positions[:,0][sys.atoms.selection], - sys.atoms.positions[:,1][sys.atoms.selection], - sys.atoms.positions[:,2][sys.atoms.selection], - marker='sphere', - size=size, - lighting=True, - color=colors) + box = sys.box.copy() + origin = np.array([0,0,0]) + traces = create_box_plot(box, origin) + + data=go.Scatter3d( + x=sys.atoms.positions[:,0][sys.atoms.selection], + y=sys.atoms.positions[:,1][sys.atoms.selection], + z=sys.atoms.positions[:,2][sys.atoms.selection], + mode='markers', + opacity=1.0, + marker=dict( + sizemode='diameter', + sizeref=750, + size=radius, + color = prop, + opacity = opacity, + colorscale = cmap, + #colorbar=dict(thickness=20, title=cmap_title), + line=dict(width=0.5, color='#455A64'), + ) + ) + traces.append(data) + + fig = go.Figure(data=traces) + fig.update_layout(scene = dict( + xaxis_title="", + yaxis_title="", + zaxis_title="", + xaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",), + yaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64"), + zaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",),), + width=700, + margin=dict( + r=10, l=10, + b=10, t=10) + ) + fig.update_layout(showlegend=False) + fig.show() + #add plot sys.remove_selection() - #plotting box - box = sys.box.copy() - origin = np.array([0,0,0]) - combos = list(itertools.combinations(range(3), 2)) - for combo in combos: - f1 = [origin, box[combo[0]], box[combo[0]]+box[combo[1]], box[combo[1]], origin] - s = combo[0] + combo[1] - t = 3-s - f2 = [origin + box[t], box[combo[0]]+ box[t], box[combo[0]]+box[combo[1]]+ box[t], box[combo[1]]+ box[t], origin + box[t]] - unn = np.vstack((f1, f2)) - ipv.plot(unn[:,0], unn[:,1], unn[:,2], color='#546e7a') - - ipv.style.box_off() - ipv.style.axes_off() - ipv.squarelim() - - #done - return ipv.gcf() + def plot_simple(sys, colors=None, height=500, width=500, size=5, ): From 50f32c284176483be1065c6631ccf1cb27896a58 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Tue, 19 Sep 2023 09:12:35 +0200 Subject: [PATCH 3/6] update plots --- src/pyscal3/atoms.py | 4 +- src/pyscal3/operations/visualize.py | 99 ++++++++++++++++++----------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/src/pyscal3/atoms.py b/src/pyscal3/atoms.py index fbffa85..f113257 100644 --- a/src/pyscal3/atoms.py +++ b/src/pyscal3/atoms.py @@ -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]] diff --git a/src/pyscal3/operations/visualize.py b/src/pyscal3/operations/visualize.py index 6cadebe..937a4c9 100644 --- a/src/pyscal3/operations/visualize.py +++ b/src/pyscal3/operations/visualize.py @@ -139,7 +139,8 @@ def plot_by_property(sys, colorby, ids=None, indices=None, condition=None, cmap = 'viridis', - height=500, width=500, size=5, ): + radius=10, + opacity=1.0): try: @@ -147,15 +148,15 @@ def plot_by_property(sys, colorby, ids=None, except ImportError: print("Install plotly for visualisation") - colorby = colorby.copy().astype(int) + #colorby = colorby.copy().astype(int) sys.apply_selection(ids=ids, indices=indices, condition=condition) colorby = [x for count, x in enumerate(colorby) if sys.atoms.selection[count]] - colorby = colorby.copy() - a = min(colorby) - b = max(colorby) - prop = (colorby - a)/(b - a) + #colorby = colorby.copy() + #a = min(colorby) + #b = max(colorby) + #prop = (colorby - a)/(b - a) box = sys.box.copy() origin = np.array([0,0,0]) @@ -171,7 +172,7 @@ def plot_by_property(sys, colorby, ids=None, sizemode='diameter', sizeref=750, size=radius, - color = prop, + color = colorby, opacity = opacity, colorscale = cmap, #colorbar=dict(thickness=20, title=cmap_title), @@ -211,49 +212,75 @@ def plot_by_property(sys, colorby, ids=None, -def plot_simple(sys, colors=None, height=500, width=500, size=5, ): +def plot_simple(sys, colors=None, + radius=10, + opacity=1.0 ): try: - import ipyvolume as ipv + from plotly import graph_objs as go except ImportError: - print("Install ipyvolume for visualisation") + print("Install plotly for visualisation") + if colors is None: colors =[ '#33a02c', '#fb9a99', '#e31a1c', '#a6cee3', '#1f78b4', '#b2df8a', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'] + comp_ints = sys.atoms.composition_ints if len(comp_ints) > len(colors): warnings.warn('less colors than number of species, expect repetitions, or provide more colors') diff = np.ceil((len(comp_ints)-len(colors))/len(colors)) colors = colors*diff - - fig = ipv.figure(debug=False, width=width, height=height) - for key in comp_ints.keys(): - scatter = ipv.scatter(sys.atoms.positions[:,0][sys.atoms.types == key], - sys.atoms.positions[:,1][sys.atoms.types == key], - sys.atoms.positions[:,2][sys.atoms.types == key], - marker='sphere', - size=size, - lighting=True, - color=colors[key-1]) - - #plotting box + box = sys.box.copy() origin = np.array([0,0,0]) - combos = list(itertools.combinations(range(3), 2)) - for combo in combos: - f1 = [origin, box[combo[0]], box[combo[0]]+box[combo[1]], box[combo[1]], origin] - s = combo[0] + combo[1] - t = 3-s - f2 = [origin + box[t], box[combo[0]]+ box[t], box[combo[0]]+box[combo[1]]+ box[t], box[combo[1]]+ box[t], origin + box[t]] - unn = np.vstack((f1, f2)) - ipv.plot(unn[:,0], unn[:,1], unn[:,2], color='#546e7a') - - ipv.style.box_off() - ipv.style.axes_off() - ipv.squarelim() + traces = create_box_plot(box, origin) + + for key in comp_ints.keys(): + data=go.Scatter3d( + x=sys.atoms.positions[:,0][sys.atoms.types == key], + y=sys.atoms.positions[:,1][sys.atoms.types == key], + z=sys.atoms.positions[:,2][sys.atoms.types == key], + mode='markers', + opacity=1.0, + marker=dict( + sizemode='diameter', + sizeref=750, + size=radius, + color = colors[key-1], + opacity = opacity, + #colorbar=dict(thickness=20, title=cmap_title), + line=dict(width=0.5, color='#455A64'), + ) + ) + + traces.append(data) + + fig = go.Figure(data=traces) + fig.update_layout(scene = dict( + xaxis_title="", + yaxis_title="", + zaxis_title="", + xaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",), + yaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64"), + zaxis = dict( + showticklabels=False, + showbackground=False, + zerolinecolor="#455A64",),), + width=700, + margin=dict( + r=10, l=10, + b=10, t=10) + ) + fig.update_layout(showlegend=False) + return fig.show() + - #done - return ipv.gcf() \ No newline at end of file From 673da1aa64b06263a1f060aa4be8b89de0b07b78 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Tue, 19 Sep 2023 09:16:28 +0200 Subject: [PATCH 4/6] update plots --- src/pyscal3/operations/visualize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyscal3/operations/visualize.py b/src/pyscal3/operations/visualize.py index 937a4c9..7507bbf 100644 --- a/src/pyscal3/operations/visualize.py +++ b/src/pyscal3/operations/visualize.py @@ -281,6 +281,8 @@ def plot_simple(sys, colors=None, b=10, t=10) ) fig.update_layout(showlegend=False) + fig['layout'].update(scene=dict(aspectmode="data")) + return fig.show() From 4c34ab85ae09fdb80ab41f21939312ff8b4307ff Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Tue, 19 Sep 2023 09:24:01 +0200 Subject: [PATCH 5/6] update plots# --- src/pyscal3/operations/visualize.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pyscal3/operations/visualize.py b/src/pyscal3/operations/visualize.py index 7507bbf..67bc979 100644 --- a/src/pyscal3/operations/visualize.py +++ b/src/pyscal3/operations/visualize.py @@ -132,7 +132,8 @@ def plot_by_selection(sys, radius=10, b=10, t=10) ) fig.update_layout(showlegend=False) - fig.show() + fig['layout'].update(scene=dict(aspectmode="data")) + return fig.show() def plot_by_property(sys, colorby, ids=None, @@ -205,9 +206,10 @@ def plot_by_property(sys, colorby, ids=None, b=10, t=10) ) fig.update_layout(showlegend=False) - fig.show() + fig['layout'].update(scene=dict(aspectmode="data")) #add plot sys.remove_selection() + return fig.show() @@ -282,7 +284,6 @@ def plot_simple(sys, colors=None, ) fig.update_layout(showlegend=False) fig['layout'].update(scene=dict(aspectmode="data")) - return fig.show() From 31cb93f36ba677f1e61f94693b251bf100988e88 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Tue, 19 Sep 2023 12:28:26 +0200 Subject: [PATCH 6/6] update gb creation and plotting --- src/pyscal3/csl.py | 11 ++++++++++- src/pyscal3/operations/operations.py | 13 +++++++------ src/pyscal3/operations/visualize.py | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/pyscal3/csl.py b/src/pyscal3/csl.py index 61ebcfd..ec28590 100644 --- a/src/pyscal3/csl.py +++ b/src/pyscal3/csl.py @@ -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 @@ -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 diff --git a/src/pyscal3/operations/operations.py b/src/pyscal3/operations/operations.py index 820aba2..f34eb27 100644 --- a/src/pyscal3/operations/operations.py +++ b/src/pyscal3/operations/operations.py @@ -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 diff --git a/src/pyscal3/operations/visualize.py b/src/pyscal3/operations/visualize.py index 67bc979..e53f9ea 100644 --- a/src/pyscal3/operations/visualize.py +++ b/src/pyscal3/operations/visualize.py @@ -102,7 +102,7 @@ def plot_by_selection(sys, radius=10, color = cFalse, opacity = opacity, #colorscale = colorscale, - #colorbar=dict(thickness=20, title=cmap_title), + #colorbar=dict(thickness=20), line=dict(width=0.5, color='#455A64') ) ) @@ -176,7 +176,7 @@ def plot_by_property(sys, colorby, ids=None, color = colorby, opacity = opacity, colorscale = cmap, - #colorbar=dict(thickness=20, title=cmap_title), + colorbar=dict(thickness=20), line=dict(width=0.5, color='#455A64'), ) )