From 0cec37f3fc53fbc4cec887b7809a0f0281134b94 Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Wed, 16 Sep 2015 11:02:30 +0200 Subject: [PATCH] Added 'type_of_ion' list to class Poscar A list 'type_of_ion' mapping ion index to their types is added to class Poscar. A corresponding test is also added. --- python/converters/vasp/python/vaspio.py | 4 +++ .../vasp/test/_vaspio/POSCAR.complex | 28 +++++++++++++++++++ .../vasp/test/_vaspio/test_poscar.py | 10 +++++++ 3 files changed, 42 insertions(+) create mode 100644 python/converters/vasp/test/_vaspio/POSCAR.complex diff --git a/python/converters/vasp/python/vaspio.py b/python/converters/vasp/python/vaspio.py index f3d96105..473f7a49 100644 --- a/python/converters/vasp/python/vaspio.py +++ b/python/converters/vasp/python/vaspio.py @@ -173,7 +173,11 @@ class Poscar: # Read atomic positions self.q_types = [] + self.type_of_ion = [] for it in xrange(self.ntypes): +# Array mapping ion index to type + self.type_of_ion += self.nions[it] * [it] + q_at_it = np.zeros((self.nions[it], 3)) for iq in xrange(self.nions[it]): sline = readline_remove_comments() diff --git a/python/converters/vasp/test/_vaspio/POSCAR.complex b/python/converters/vasp/test/_vaspio/POSCAR.complex new file mode 100644 index 00000000..c7693ced --- /dev/null +++ b/python/converters/vasp/test/_vaspio/POSCAR.complex @@ -0,0 +1,28 @@ +NdNiO3 +1.0 + 5.3871197701 0.0000000000 0.0000000000 + 0.0000000000 5.3826699257 0.0000000000 + 0.0000000000 0.0000000000 7.6093997955 + Nd Ni O + 4 4 12 +Direct + 0.995800018 0.035000000 0.250000000 + 0.004199982 0.964999974 0.750000000 + 0.495800018 0.465000004 0.750000000 + 0.504199982 0.535000026 0.250000000 + 0.500000000 0.000000000 0.000000000 + 0.000000000 0.500000000 0.000000000 + 0.500000000 0.000000000 0.500000000 + 0.000000000 0.500000000 0.500000000 + 0.069300003 0.489699990 0.250000000 + 0.930700004 0.510300040 0.750000000 + 0.569299996 0.010300010 0.750000000 + 0.430700004 0.989699960 0.250000000 + 0.716600001 0.287099987 0.039500002 + 0.283399999 0.712900043 0.960500002 + 0.216600001 0.212900013 0.960500002 + 0.783399999 0.787099957 0.039500002 + 0.283399999 0.712900043 0.539499998 + 0.716600001 0.287099987 0.460500002 + 0.783399999 0.787099957 0.460500002 + 0.216600001 0.212900013 0.539499998 diff --git a/python/converters/vasp/test/_vaspio/test_poscar.py b/python/converters/vasp/test/_vaspio/test_poscar.py index bfe4420c..10f7b395 100644 --- a/python/converters/vasp/test/_vaspio/test_poscar.py +++ b/python/converters/vasp/test/_vaspio/test_poscar.py @@ -18,6 +18,7 @@ class TestPoscar(mytest.MyTestCase): Scenarios: - correct POSCAR file + - check 'type_of_ion' array for a complex POSCAR file """ # Scenario 1 @@ -41,3 +42,12 @@ class TestPoscar(mytest.MyTestCase): expected = 'POSCAR.example.out' self.assertFileEqual(testout, expected) +# Scenario 2 + def test_type_of_ion(self): + filename = 'POSCAR.complex' + poscar = Poscar() + poscar.from_file(vasp_dir='./', poscar_filename=filename) + + test_types = 4 * [0] + 4 * [1] + 12 * [2] + self.assertListEqual(test_types, poscar.type_of_ion) +