Skip to content

Commit

Permalink
Add utility and fix bug with dual_monoalyer (#31)
Browse files Browse the repository at this point in the history
* fix inaccuracy in separation value in dual_monolayer

* add utitil to calculate boundary position of a compound
  • Loading branch information
daico007 authored Sep 13, 2023
1 parent 508eee3 commit c0e9e63
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions surface_coatings/monolayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Routines to create (dual) monolayer systems."""
from copy import deepcopy
from warnings import warn
from surface_coatings.utils.utils import boundary_positions

import mbuild as mb
import numpy as np
Expand Down Expand Up @@ -166,8 +167,10 @@ def __init__(

bot_box = bottom.get_boundingbox()
top_box = top.get_boundingbox()
z_val = bot_box.lengths[2]
top.translate([0, 0, z_val + separation])
top_min, top_max = boundary_positions(top)
bot_min, bot_max = boundary_positions(bottom)

top.translate([0, 0, bot_max[2] - top_min[2] + separation])

if surface_idx:
if isinstance(surface_idx, dict):
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions surface_coatings/utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import mbuild as mb


def boundary_positions(compounds):
xs, ys, zs = list(), list(), list()
if isinstance(compounds, mb.Compound):
for part in compounds.particles():
xs.append(part.pos[0])
ys.append(part.pos[1])
zs.append(part.pos[2])
elif isinstance(compounds, (list, tuple)):
for molecule in compounds:
for part in molecule.particles():
xs.append(part.pos[0])
ys.append(part.pos[1])
zs.append(part.pos[2])

minima = (min(xs), min(ys), min(zs))
maxima = (max(xs), max(ys), max(zs))
return np.array(minima), np.array(maxima)

0 comments on commit c0e9e63

Please sign in to comment.