Importing custom spice model

Hello everyone,

I am struggling with importing the C-Spin MTJ Spice-model into KiCad (link: C-SPIN: MTJ SPICE Model).
I am new to KiCad and dont know too much about ngspice, but was able to run a small simulation with ngspice from the terminal with this code:
“”"

.include 'MTJ_Model/MTJ_model_IuE_circular.inc'

*** Options ************************************************************************
.option post
.save

*** Voltage biasing to MTJ *********************************************************
.param vmtj='-1.0'
V1 1 0 'vmtj'
XMTJ1 1 0 MTJ lx='30n' ly='30n' lz='1.0n' Ms0='1100' P0='0.707' alpha='0.035' Tmp0='300' RA0='6.0' MA='1' ini='0' Kp='9.0e6'
*XMTJ1 1 0 MTJ lx='40n' ly='40n' lz='1.7n' Ms0='1200' P0='0.707' alpha='0.02' Tmp0='300' RA0='17' MA='1' ini='0' Kp='9.0e6'
*** Analysis ***********************************************************************
* .param pw='10ns' 
* .tran 1p 'pw' START=1.0e-18  uic $sweep vmtj 0.3 0.6 0.1
* .op
* .tran 1p 'pw' 1.0e-18  uic $sweep vmtj 0.3 0.6 0.1

.control
* op
tran 1p 10n 1.0e-18 
*uic $ sweep vmtj 0.4 0.5 0.01
plot v(XMTJ1.Mz) v(XMTJ1.Mx) v(XMTJ1.My)
plot v(XMTJ1.XRA.rmtj)
plot i(V1) I(V.XMTJ1.Ve1)
*plot v(XMTJ1.XLLG.Hdz)
plot v(XMTJ1.Is)
*plot v(XMTJ1.XLLG.Ms) 

gnuplot pap v(XMTJ1.Mz)
.endc

* .meas tsw0 when v(XMTJ1.XLLG.Mz)='0'
* .meas iwr find i(XMTJ1.ve1) at 1ns
* .meas thermal_stability find v(XMTJ1.XLLG.thste) at 1ns

.end

Afterwards I created a symbol in the symbol editor as shown in the KiCad tutorials - then I open “Simulation Model” and use a subfolder containing the four “.inc” files.
I chose “MTJ” as the Model and the default parameters defined in the .inc file show up.
so to this point it seems to work?
But when trying to simulate I got a bunch of different errors.
Would anyone be willing to show me how to import the model correctly and just run the simplest simulation?

here is the code for the MTJ_model.inc, that can be found in the zip-files on the website:

.include 'LLG_solver.inc'
.include 'Resistor.inc'
.include 'HeatDF.inc'

.subckt MTJ e1 e2 lx='65n' ly='130n' lz='1.8n' Ms0='1075' P0='0.715' alpha='0.01' Tmp0='300' RA0='5.4' MA='0.0' ini='1'

XRA   ex e2 Mx My Mz Tmp thi RA lx='lx' ly='ly' P0='P0' RA0='RA0' MA='MA' 
XLLG  Mx My Mz Is Ias Tmp thi LLG lx='lx' ly='ly' lz='lz' Ms0='Ms0' P0='P0' alpha='alpha' MA='MA' ini='ini'
XHD   Ihd Tmp HD lx='lx' ly='ly' lz='lz' Tmp0='Tmp0'

*** Internal top electrode of MTJ ***************
Ve1 e1 ex 0


*** Asymetry of write current ************************
*** positive bias:Ias=Iatp, negative bias:Ias=Ipta ***
*** Iatp will generate more spin current. ************ 
.param Iatp='1'
.param Ipta='1/1.5'
E_Ias Ias 0 vol='(1+(v(e1)-v(e2))/abs(v(e1)-v(e2)))*(Iatp-Ipta)/2+Ipta'


*** Charge current passing through MTJ stack *************
*** Imtj is fed to LLG and Head_Diffusion models *********
G_Imtj1 0 Is cur='-I(Ve1)'
G_Imtj2 0 Ihd cur='-I(Ve1)'



.ends

I hope someone can help me here, thanks in advance!

What are these error messages?

What probably is happening: When you have chosen model MTJ, it is loaded into ngspice from .subckt MTJ … until .ends.

Thus the three include files

.include 'LLG_solver.inc'
.include 'Resistor.inc'
.include 'HeatDF.inc'

are missing.

Two possible remedies (without knowing the error messages):

Shift these three lines into the subcircuit (place them after the .subckt line).
or
Add these three lines into a text box and place them onto the Eeschema canvas. Thus they are in any case added to the ngspice netlist.