Skip to content

Commit

Permalink
Set up test
Browse files Browse the repository at this point in the history
  • Loading branch information
siuwuncheung committed Dec 3, 2024
1 parent 8f61523 commit a09ca14
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/PinnedH2O_3DOF/coords.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
O1 1 0.00 0.00 0.00 0
H1 2 1.12 1.45 0.00 1
H2 2 1.12 -1.45 0.00 1
31 changes: 31 additions & 0 deletions tests/PinnedH2O_3DOF/mgmol.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
verbosity=1
xcFunctional=PBE
FDtype=Mehrstellen
[Mesh]
nx=64
ny=64
nz=64
[Domain]
ox=-6.
oy=-6.
oz=-6.
lx=12.
ly=12.
lz=12.
[Potentials]
pseudopotential=pseudo.O_ONCV_PBE_SG15
pseudopotential=pseudo.H_ONCV_PBE_SG15
[Run]
type=quench
[Thermostat]
type=Berendsen
temperature=1000.
relax_time=800.
[Quench]
max_steps=100
atol=1.e-8
[Orbitals]
initial_type=Random
initial_width=2.
[Restart]
output_level=4
91 changes: 91 additions & 0 deletions tests/PinnedH2O_3DOF/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python
import sys
import os
import subprocess
import string

print("Test PinnedH2O_3DOF...")

nargs=len(sys.argv)

mpicmd = sys.argv[1]+" "+sys.argv[2]+" "+sys.argv[3]
for i in range(4,nargs-4):
mpicmd = mpicmd + " "+sys.argv[i]
print("MPI run command: {}".format(mpicmd))

exe = sys.argv[nargs-4]
inp = sys.argv[nargs-3]
coords = sys.argv[nargs-2]
print("coordinates file: %s"%coords)

#create links to potentials files
dst1 = 'pseudo.O_ONCV_PBE_SG15'
dst2 = 'pseudo.H_ONCV_PBE_SG15'
src1 = sys.argv[nargs-1] + '/' + dst1
src2 = sys.argv[nargs-1] + '/' + dst2

if not os.path.exists(dst1):
print("Create link to %s"%dst1)
os.symlink(src1, dst1)
if not os.path.exists(dst2):
print("Create link to %s"%dst2)
os.symlink(src2, dst2)

#run
command = "{} {} -c {} -i {}".format(mpicmd,exe,inp,coords)
print("Run command: {}".format(command))
output = subprocess.check_output(command,shell=True)
lines=output.split(b'\n')

#analyse output
energies=[]
for line in lines:
if line.count(b'%%'):
print(line)
words=line.split()
words=words[5].split(b',')[0]
energy = words.decode()
if line.count(b'achieved'):
energies.append(energy)

flag=0
forces=[]
for line in lines:
if flag>0:
print(line)
words=line.split(b' ')
forces.append(words[1].decode())
forces.append(words[2].decode())
forces.append(words[3].decode())
flag=flag-1
if line.count(b'Forces:'):
flag=2


print("Check energies...")
print( energies )
if len(energies)<2:
print("Expected two converged energies")
sys.exit(1)

tol = 1.e-6
diff=eval(energies[1])-eval(energies[0])
print(diff)
if abs(diff)>tol:
print("Energies differ: {} vs {} !!!".format(energies[0],energies[1]))
sys.exit(1)

print("Check forces...")
print(forces)
flag=0
for i in range(6):
diff=eval(forces[i+6])-eval(forces[i])
print(diff)
if abs(diff)>1.e-3:
print("Forces difference larger than tol")
flag=1
if flag>0:
sys.exit(1)

print("Test SUCCESSFUL!")
sys.exit(0)

0 comments on commit a09ca14

Please sign in to comment.