Aufgrund eines Versionsupdates wird GitLab am 17.12. zwischen 9:00 und 9:30 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to a version upgrade, GitLab won't be accessible at 17.12. between 9 and 9:30 a.m.

Commit 6c3a1878 authored by Nils Cedric Holle's avatar Nils Cedric Holle

Fix stacking + export

parent a3ff975e
*.pyc
.vscode/*
api.key
.mypy_cache/*
......@@ -5,6 +5,7 @@ import numpy as np
from ase import Atoms
from ase.cell import Cell
from sympy import Point3D
from typing import List, Tuple
from layerdeposition.backend.plane import LDPlane, getSurroundingCellPoints
from layerdeposition.backend.boundingrect import minBoundingRect
......@@ -32,7 +33,7 @@ def stackLayers(model, collapse: bool = True,
elif len(atoms) == 1:
return atoms[0]
else:
coords, outAtoms = [], Atoms()
outAtoms = Atoms()
height = 0
for l in layers:
......@@ -40,20 +41,30 @@ def stackLayers(model, collapse: bool = True,
for a in atoms:
outAtoms += a
outAtoms.set_cell(stackCells(model)[0])
outAtoms.set_cell(stackCells(model, collapse)[0])
return outAtoms
def getTranslations(layers: list, i: int, collapse: bool):
l = layers[i]
atoms = l.getFinalAtoms()
translations = np.zeros((len(atoms), 3))
for j in range(len(atoms)):
for k in range(i):
if collapse and l.collapsible:
for k in range(i):
if collapse and l.collapsible:
for j in range(len(atoms)):
translations[j, 2] += layers[k].zProfile(
atoms[j].x, atoms[j].y)
else:
if collapse and layers[k].collapsible and i > 0 and k > 0:
tm1 = (np.max(getTranslations(layers, k, collapse))
- np.max(getTranslations(layers, k - 1, collapse)))
for j in range(len(atoms)):
translations[j, 2] += tm1
else:
translations[j, 2] += layers[k].height
h = layers[k].height
for j in range(len(atoms)):
translations[j, 2] += h
return translations
......@@ -62,7 +73,7 @@ def stackLayerInterfaces(model, plane: LDPlane,
collapse: bool = False,
interfaceWidth: float = 1.) -> Atoms:
if atomList:
atoms = []
atoms: List[Atoms] = []
else:
atoms = Atoms()
......@@ -89,7 +100,7 @@ def stackLayerInterfaces(model, plane: LDPlane,
return atoms
def stackCells(model, collapse: bool) -> (Cell, np.ndarray):
def stackCells(model, collapse: bool) -> Tuple[Cell, np.ndarray]:
layers = model.layers
if len(layers) == 0:
......@@ -107,8 +118,9 @@ def stackCells(model, collapse: bool) -> (Cell, np.ndarray):
for p in list(pol1.exterior.coords) + list(pol2.exterior.coords):
coords.append((p[0] + l.cellShift[0], p[1] + l.cellShift[1]))
if collapse and l.collapsible and i > 0:
translations = getTranslations(layers, i, collapse)
height += np.max(translations)
height += (np.max(getTranslations(layers, i, collapse)) -
np.max(getTranslations(layers, i - 1, collapse)))
else:
height += l.height
......
......@@ -3,7 +3,9 @@ import re
from collections import OrderedDict
from copy import deepcopy
from io import StringIO
from typing import Tuple
import numpy as np
from ase import Atoms, io
from PyQt5.QtCore import *
from PyQt5.QtGui import *
......@@ -14,7 +16,7 @@ from layerdeposition.backend.layer import Layer
from layerdeposition.backend.operations import *
from layerdeposition.backend.plane import *
from layerdeposition.backend.signal import Signal
from layerdeposition.backend.stack import stackLayers, stackCells
from layerdeposition.backend.stack import stackCells, stackLayers
def rreplace(s: str, old: str, new: str, occurrence: int):
......@@ -40,9 +42,11 @@ class TreeModel(QStandardItemModel):
@property
def atoms(self) -> Atoms:
atoms = stackLayers(self, self.__collapse)
atoms.set_pbc(True)
return atoms
def cell(self) -> np.ndarray:
@property
def cell(self) -> Tuple[np.ndarray, np.ndarray]:
return stackCells(self, self.collapse)
@property
......@@ -142,7 +146,9 @@ class TreeModel(QStandardItemModel):
self.update()
def export(self, filename: str):
io.write(filename, self.atoms)
atoms = self.atoms
atoms.translate(-self.cell[1])
io.write(filename, atoms)
def addLayer(self, name: str, layer: Layer, update: bool = True):
if name not in self.__layers:
......
......@@ -95,7 +95,7 @@ class View3D(View):
self.__chkCollapse.setChecked(self._model.collapse)
self.__chkRect.setChecked(self._model.rectangularCell)
atoms = model.atoms
cell, shift = model.cell()
cell, shift = model.cell
cPos = self.__renderer.GetActiveCamera().GetPosition()
self.__renderer.RemoveAllViewProps()
self.__renderer.Clear()
......
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