2015-08-10 11:32:08 +02:00
|
|
|
r"""
|
|
|
|
Tests for class 'Poscar' from module 'vaspio'
|
|
|
|
"""
|
2015-10-16 11:52:33 +02:00
|
|
|
import os
|
2020-04-08 22:07:20 +02:00
|
|
|
import rpath
|
2015-10-16 11:52:33 +02:00
|
|
|
_rpath = os.path.dirname(rpath.__file__) + '/'
|
|
|
|
|
2020-04-08 22:07:20 +02:00
|
|
|
import mytest
|
2015-08-10 11:32:08 +02:00
|
|
|
import numpy as np
|
2018-09-06 13:48:24 +02:00
|
|
|
from triqs_dft_tools.converters.plovasp.vaspio import Poscar
|
2015-08-10 11:32:08 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# TestPoscar
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
class TestPoscar(mytest.MyTestCase):
|
|
|
|
"""
|
|
|
|
Function:
|
|
|
|
|
|
|
|
def Poscar.from_file(vasp_dir, poscar_filename)
|
|
|
|
|
|
|
|
Scenarios:
|
|
|
|
- correct POSCAR file
|
2015-09-16 11:02:30 +02:00
|
|
|
- check 'type_of_ion' array for a complex POSCAR file
|
2015-08-10 11:32:08 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
# Scenario 1
|
|
|
|
def test_example(self):
|
|
|
|
filename = 'POSCAR.example'
|
|
|
|
poscar = Poscar()
|
2015-10-16 11:52:33 +02:00
|
|
|
poscar.from_file(vasp_dir=_rpath, poscar_filename=filename)
|
2015-08-10 11:32:08 +02:00
|
|
|
|
2015-10-16 11:52:33 +02:00
|
|
|
testout = _rpath + 'POSCAR.example.out.test'
|
2015-08-10 11:32:08 +02:00
|
|
|
with open(testout, 'w') as f:
|
|
|
|
writeline = lambda s: f.write(s + '\n')
|
|
|
|
writeprop = lambda pname: writeline("%s = %s"%(pname, poscar.__dict__[pname]))
|
|
|
|
|
|
|
|
writeprop('nq')
|
|
|
|
writeprop('ntypes')
|
|
|
|
writeprop('nions')
|
|
|
|
writeprop('el_names')
|
|
|
|
writeline("a_brav:\n%s"%(poscar.a_brav))
|
|
|
|
writeline("q_types:\n%s"%(poscar.q_types))
|
|
|
|
|
2015-10-16 11:52:33 +02:00
|
|
|
expected = _rpath + 'POSCAR.example.out'
|
2015-08-10 11:32:08 +02:00
|
|
|
self.assertFileEqual(testout, expected)
|
|
|
|
|
2015-09-16 11:02:30 +02:00
|
|
|
# Scenario 2
|
|
|
|
def test_type_of_ion(self):
|
|
|
|
filename = 'POSCAR.complex'
|
|
|
|
poscar = Poscar()
|
2015-10-16 11:52:33 +02:00
|
|
|
poscar.from_file(vasp_dir=_rpath, poscar_filename=filename)
|
2015-09-16 11:02:30 +02:00
|
|
|
|
|
|
|
test_types = 4 * [0] + 4 * [1] + 12 * [2]
|
|
|
|
self.assertListEqual(test_types, poscar.type_of_ion)
|
|
|
|
|