4
$\begingroup$

I have two surfaces named POSCAR1 and POSCAR2. I want to stack the surface of POSCAR2 on POSCAR1 to form an interface and also to match their lattice constants. I tried a solution here by adding it as an adsorbate but couldn't rotate. Any python code will be appreciated. I have attached the two POSCARS.

CoCrFeNi
   1.00000000000000     
     9.9633502299999996    0.0000000000000000    0.0000000000000000
    -4.9733836199999999    8.6618479100000005    0.0000000000000000
     0.0000000000000000    0.0000000000000000   40.4368920000000003
   Co   Cr   Fe   Ni
    24    24    24    24
Selective dynamics
Direct
  0.5612360243849388  0.9099052137287840  0.6250221820654160   T   T   T
  0.2356071120850486  0.2518526753215678  0.5772064214469697   T   T   T
  0.2348146468815286  0.7507696751875000  0.5764034425400485   T   T   T
  0.4860087088559321  0.5025000099364838  0.5766204786838768   T   T   T
  0.4832051517095323  0.9985833850246899  0.5770138532476135   T   T   T
  0.4854835901844644  0.7512215609776637  0.5763813008840900   T   T   T
  0.2355456895711744  0.9978683794875377  0.5777498674746212   T   T   T
  0.9867436499750243  0.5059613373927444  0.5769244369303035   T   T   T
  0.9038462779907266  0.5846022973376531  0.5260416228921621   T   T   T
  0.5716581887774268  0.9201204041921329  0.4758342950788617   F   F   F
  0.5741257856744610  0.4187527924396477  0.4757376011984320   F   F   F
  0.8221917385325952  0.1698063756466937  0.4754235315612263   F   F   F
  0.8188510224305006  0.6661687044098628  0.4754012746578056   F   F   F
  0.8238998402551019  0.4200678697901523  0.4748374331044047   F   F   F
  0.5727204154956951  0.6689043793196774  0.4747973706782389   F   F   F
  0.3230897361863398  0.1691307692332842  0.4746252506250954   F   F   F
  0.2362167951761762  0.2470966960213019  0.4240635012206155   F   F   F
  0.9075250613866288  0.5865598256619577  0.3747389883475734   F   F   F
  0.9099926467579991  0.0851921908197042  0.3746422944671437   F   F   F
  0.1580586012731757  0.8362458075069128  0.3743282248299380   F   F   F
  0.1547179181243052  0.3326081258796876  0.3743059679265173   F   F   F
  0.1597667301860781  0.0865072797151001  0.3737421263731164   F   F   F
  0.9085872881049042  0.3353438007895022  0.3737020639469506   F   F   F
  0.6589565758423106  0.8355702010934962  0.3735299438938071   F   F   F
  0.8058501908443986  0.1604085948745253  0.6276226743697434   T   T   T
  0.0711651015373968  0.1740917158429164  0.6283794021117671   T   T   T
  0.5585537014512123  0.1589400490967113  0.6274647415475056   T   T   T
  0.8408195288613217  0.4120066169412361  0.6276226664037110   T   T   T
  0.8218106695859454  0.6771528044496808  0.6304296582071180   T   T   T
  0.0835097517099495  0.4214918947625969  0.6290440423670955   T   T   T
  0.2375735696515378  0.5010054481380813  0.5770179622858687   T   T   T
  0.7358517176793846  0.5001337489919461  0.5753017076229778   T   T   T
  0.1526774569984566  0.8311508061347753  0.5260862055103875   T   T   T
  0.4012780008378368  0.8374455841948802  0.5256159156652330   T   T   T
  0.9015458337759297  0.8318449292366887  0.5267321752290328   T   T   T
  0.1650345374797721  0.0820828245082830  0.5266625182108280   T   T   T
  0.1530715796942058  0.3284398123835934  0.5256954404458725   T   T   T
  0.4037759574840217  0.0881761973292648  0.5266741240986712   T   T   T
  0.5719291831091056  0.1671338512338281  0.4751517500405313   F   F   F
  0.0726206267831913  0.1688011628918105  0.4750530777686848   F   F   F
  0.4902349088201277  0.5006121147652394  0.4250452779605283   F   F   F
  0.7387644569889744  0.5022689205818693  0.4249752923642092   F   F   F
  0.2384726428149762  0.4987219869114483  0.4248748889998737   F   F   F
  0.4894111111794288  0.7512741008171346  0.4248244400187815   F   F   F
  0.4908000549497729  0.0025951829486672  0.4244191170775409   F   F   F
  0.7393419908448990  0.7494893777233287  0.4241708289549067   F   F   F
  0.9077960227650834  0.8335732830940472  0.3740564433092430   F   F   F
  0.4084875035752731  0.8352405947520296  0.3739577710373965   F   F   F
  0.0714088580284006  0.9241042308280607  0.6266688247630529   T   T   T
  0.0712936348301734  0.6734806713146717  0.6264448440732556   T   T   T
  0.5661143764171257  0.6694797179385326  0.6276482980086926   T   T   T
  0.5826565215444279  0.4197094481854535  0.6248967461469209   T   T   T
  0.9863437963371268  0.0049281853325266  0.5778527630146324   T   T   T
  0.7299839656132034  0.7483226508951495  0.5771810032009886   T   T   T
  0.9822818352016206  0.7481102940128979  0.5771714159167410   T   T   T
  0.4836853691620328  0.2504096534801669  0.5765478188719351   T   T   T
  0.4023001272576696  0.5849271527966273  0.5256599968038801   T   T   T
  0.4052342653716023  0.3382546586388231  0.5252451653467152   T   T   T
  0.9035134348127880  0.3352264766627390  0.5263625912611249   T   T   T
  0.9027949755174263  0.0791523962176613  0.5260593633310788   T   T   T
  0.3232407866261937  0.6702789128053368  0.4755137956695563   F   F   F
  0.0665275574938846  0.4173909583226560  0.4755078604953127   F   F   F
  0.3245013047405436  0.4173221508342095  0.4749788880906110   F   F   F
  0.8209027016053341  0.9159207229719186  0.4747226864023091   F   F   F
  0.7400046718620530  0.2526014105458927  0.4255408650100989   F   F   F
  0.7373990205197032  0.9972170014700694  0.4251333163785205   F   F   F
  0.2401126400303042  0.0008789443175559  0.4246560294495438   F   F   F
  0.2420278484524303  0.7522265534676222  0.4244614051940516   F   F   F
  0.6591076592354028  0.3367183342751616  0.3744184889382680   F   F   F
  0.4023944301030866  0.0838303797924809  0.3744125537640244   F   F   F
  0.6603682004010807  0.0837616184835568  0.3738835813593226   F   F   F
  0.1567695396708118  0.5823600289929374  0.3736276269699488   F   F   F
  0.8139283773437237  0.9179970463961956  0.6264927519830703   T   T   T
  0.3316971715924403  0.4206428344420928  0.6270248681347872   T   T   T
  0.3156932809260076  0.9156706536874418  0.6266447810285281   T   T   T
  0.3193842754680041  0.6705125009466922  0.6268440812499967   T   T   T
  0.3204197280025719  0.1699424665767754  0.6272751272551228   T   T   T
  0.7346622986391906  0.2521520822199035  0.5767044378177472   T   T   T
  0.7337753457319838 -0.0000484138730764  0.5764088122275434   T   T   T
  0.9859905944062034  0.2532340884891014  0.5767699223686655   T   T   T
  0.1520510767833566  0.5824068293232663  0.5262650644687904   T   T   T
  0.6539763846918202  0.0840366980125778  0.5258262367600025   T   T   T
  0.6540657686858518  0.5846162808349679  0.5256774417697333   T   T   T
  0.6542669891634135  0.3357645143656891  0.5254505398702217   T   T   T
  0.6510606874754463  0.8330745611877558  0.5256560801844358   T   T   T
  0.0765196813155740  0.9206583956286494  0.4765519565648120   F   F   F
  0.0658167894639234  0.6668927993218503  0.4761879325443701   F   F   F
  0.3165218299266357  0.9183686994568774  0.4733637787988272   F   F   F
  0.4845041515414152  0.2488359322854947  0.4251788193810739   F   F   F
  0.9902804335043385  0.7510055668940936  0.4248024304142888   F   F   F
  0.9888284822195317  0.2504328201717385  0.4244866296845942   F   F   F
  0.9943961297937989  0.9996431581306737  0.4242620822589416   F   F   F
  0.9866011241072812  0.4984118914182147  0.4231390978317506   F   F   F
  0.4123865539247760  0.5870978170984742  0.3754566498335237   F   F   F
  0.4016836620731254  0.3333322207916751  0.3750926258130818   F   F   F
  0.6523887025358377  0.5848081209267022  0.3722684720675389   F   F   F
O-rich
1.000000
     10.00748080        0.00000000        0.00000000
     -5.00374042        8.66673264        0.00000000
      0.00000000        0.00000000       36.03196650
 Cr  O
    24      36
Selective dynamics
Direct
      0.00000000        0.00000000        0.55961703 T T T
      0.16666667        0.33333335        0.54845516 T T T
      0.33333329        0.16666662        0.49366831 F F F
      0.00000000        0.00000000        0.48127432 F F F
      0.16666667        0.33333335        0.43116020 F F F
      0.33333329        0.16666662        0.41876621 F F F
      0.00000000        0.49999996        0.55961703 T T T
      0.16666668        0.83333331        0.54845516 T T T
      0.33333335        0.66666669        0.49366831 F F F
      0.00000000        0.49999996        0.48127432 F F F
      0.16666668        0.83333331        0.43116020 F F F
      0.33333335        0.66666669        0.41876621 F F F
      0.49999996        0.00000000        0.55961703 T T T
      0.66666663        0.33333335        0.54845516 T T T
      0.83333335        0.16666662        0.49366831 F F F
      0.49999996        0.00000000        0.48127432 F F F
      0.66666663        0.33333335        0.43116020 F F F
      0.83333335        0.16666662        0.41876621 F F F
      0.49999996        0.49999996        0.55961703 T T T
      0.66666664        0.83333331        0.54845516 T T T
      0.83333331        0.66666669        0.49366831 F F F
      0.49999996        0.49999996        0.48127432 F F F
      0.66666664        0.83333331        0.43116020 F F F
      0.83333331        0.66666669        0.41876621 F F F
      0.14491598        0.16765143        0.57712412 T T T
      0.02273547        0.35508401        0.57712412 T T T
      0.33234850        0.47726449        0.57712412 T T T
      0.99859339        0.15136682        0.51757826 T T T
      0.34863311        0.34722655        0.51757826 T T T
      0.15277344        0.50140656        0.51757826 T T T
      0.33333332        0.01582073        0.45621740 F F F
      0.18248737        0.16666662        0.45621740 F F F
      0.48417927        0.31751262        0.45621740 F F F
      0.14491605        0.66765151        0.57712412 T T T
      0.02273547        0.85508397        0.57712412 T T T
      0.33234857        0.97726457        0.57712412 T T T
     -0.00140656        0.65136690        0.51757826 T T T
      0.34863312        0.84722651        0.51757826 T T T
      0.15277348        0.00140659        0.51757826 T T T
      0.33333331        0.51582069        0.45621740 F F F
      0.18248739        0.66666669        0.45621740 F F F
      0.48417926        0.81751258        0.45621740 F F F
      0.64491595        0.16765143        0.57712412 T T T
      0.52273553        0.35508401        0.57712412 T T T
      0.83234847        0.47726449        0.57712412 T T T
      0.49859344        0.15136682        0.51757826 T T T
      0.84863317        0.34722655        0.51757826 T T T
      0.65277344        0.50140656        0.51757826 T T T
      0.83333338        0.01582073        0.45621740 F F F
      0.68248739        0.16666662        0.45621740 F F F
      0.98417933        0.31751262        0.45621740 F F F
      0.64491601        0.66765151        0.57712412 T T T
      0.52273547        0.85508397        0.57712412 T T T
      0.83234853        0.97726457        0.57712412 T T T
      0.49859340        0.65136690        0.51757826 T T T
      0.84863317        0.84722651        0.51757826 T T T
      0.65277344        0.00140659        0.51757826 T T T
      0.83333328        0.51582069        0.45621740 F F F
      0.68248745        0.66666669        0.45621740 F F F
      0.98417923        0.81751258        0.45621740 F F F
$\endgroup$
3
  • $\begingroup$ vaspkit and atomsk could do this. $\endgroup$ Aug 24, 2023 at 7:11
  • $\begingroup$ @TieyuanBian I have vaspkit but it's only meant for those already in it's database. 2D materials. If there's a way kindly show me. Or you can use the poscars and do it for me too see $\endgroup$ Aug 24, 2023 at 15:08
  • $\begingroup$ I have answered a similar question here. If you want to rotate a structure, just simply do atoms.rotate(). ASE can literally manipulate atoms however you want once you realize a structure is essentially just a Numpy array. Please read more into the ASE documentation. $\endgroup$
    – Shaun Han
    Aug 26, 2023 at 23:08

1 Answer 1

2
$\begingroup$

ASE

You could achieve the stacking using the Atomic Simulation Environment (ASE) python library.

Below I have attached a sample code for stacking using the 2 POSCAR files you have attached. Also, I have visualized the POSCARs before and after stacking.

import numpy as np
from ase.io import read, write
from ase.build import stack
import matplotlib.pyplot as plt

# Load the two POSCAR files
poscar1 = read("POSCAR1")
poscar2 = read("POSCAR2")

# Match the lattice constants
scaling_factor = poscar1.get_cell_lengths_and_angles()[:3] / poscar2.get_cell_lengths_and_angles()[:3]
poscar2.set_cell(poscar2.get_cell() * scaling_factor, scale_atoms=True)

# Shift the second structure to align with the first
shift = poscar1.get_center_of_mass() - poscar2.get_center_of_mass()
poscar2.translate(shift)

# Combine the two structures
combined_structure = stack(poscar1, poscar2, axis=2)

# Write the combined structure to a new POSCAR file
write("Combined_POSCAR.vasp", combined_structure)

# Visualize the original POSCARs
from ase.visualize import view

# POSCAR 1
view(poscar1, viewer="x3d")

enter image description here

# POSCAR 2
view(poscar2, viewer="x3d")

enter image description here

view(combined_structure, viewer="x3d")

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you for the answer but it appears the bottom of POSCAR2 is stacked on POSCAR1. I am looking for the reverse so that the oxygen-terminated surface is in contact with POSCAR1. Also your code doesn't say anywhere how to control the distance between the structures $\endgroup$ Aug 25, 2023 at 8:10
  • 1
    $\begingroup$ Please read the code properly. You can swap the places where poscar1 is used to poscar2. There are also comments to help you understand what the code is doing. $\endgroup$ Aug 25, 2023 at 9:59
  • 1
    $\begingroup$ the reason I am saying this is that the slab is centered in a vacuum and from your code you can see the wide gap between the two poscars. Also, I want the top surface of POSCAR2 to be attached to the top surface of POSCAR1. Your code doesn't do that. Thanks by the way. $\endgroup$ Aug 25, 2023 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .