add_force.lua
local force_file = nil
local flos = require "flos"
local Unit = siesta.Units
local add_force = {}
local read_fa = function(filename)
local file = io.open(filename, "r")
local na = tonumber(file:read())
local F = flos.Array.zeros(na, 3)
local i = 0
local function tovector(s)
local t = {}
s:gsub('%S+', function(n) t[#t+1] = tonumber(n) end)
return t
end
for i = 1, na do
local line = file:read()
if line == nil then break end
local v = tovector(line)
F[i][1] = v[2]
F[i][2] = v[3]
F[i][3] = v[4]
end
file:close()
return flos.Array.from(F)
end
function siesta_comm()
if siesta.state == siesta.INITIALIZE then
add_force = read_fa(force_file) / Unit.Ang * Unit.eV
IOprint("\nLUA Added forces")
end
if siesta.state == siesta.FORCES then
siesta.receive({"geom.fa"})
siesta.geom.fa = flos.Array.from(siesta.geom.fa) + add_force
siesta.send({"geom.fa"})
end
end