Skip to content

Commit 2141819

Browse files
committed
bug: fixed dynamic in VASP car files
Signed-off-by: Nick Papior <[email protected]>
1 parent 42238b1 commit 2141819

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

sisl/io/vasp/car.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ def _setup(self, *args, **kwargs):
2323
self._scale = 1.
2424

2525
@sile_fh_open()
26-
def write_geometry(self, geometry, fixed=False):
26+
def write_geometry(self, geometry, dynamic=True):
2727
r""" Writes the geometry to the contained file
2828
2929
Parameters
3030
----------
3131
geometry : Geometry
3232
geometry to be written to the file
33-
fixed : bool or list, optional
34-
define which atoms to be fixed in the VASP run
33+
dynamic : bool or list, optional
34+
define which atoms are dynamic in the VASP run (default is True,
35+
which means all atoms are dynamic)
3536
3637
Examples
3738
--------
3839
>>> car = carSileVASP('POSCAR', 'w')
3940
>>> geom = geom.graphene()
40-
>>> geom.write(car, fixed=False) # fix none
41-
>>> geom.write(car, fixed=[True, (False, True, False)]) # fix 1st and y coordinate of 2nd
41+
>>> geom.write(car, dynamic=False) # fix all atoms
42+
>>> geom.write(car, dynamic=[False, (True, False, True)]) # fix 1st and y coordinate of 2nd
4243
"""
4344
# Check that we can write to the file
4445
sile_raise_write(self)
@@ -80,8 +81,8 @@ def write_geometry(self, geometry, fixed=False):
8081
self._write('Selective dynamics\n')
8182
self._write('Cartesian\n')
8283

83-
if isinstance(fixed, bool):
84-
fixed = [fixed] * len(geometry)
84+
if isinstance(dynamic, bool):
85+
dynamic = [dynamic] * len(geometry)
8586

8687
b2s = {True: 'T', False: 'F'}
8788
def todyn(fix):
@@ -91,7 +92,7 @@ def todyn(fix):
9192

9293
fmt = '{:18.9f} ' * 3
9394
for ia in geometry:
94-
self._write(fmt.format(*geometry.xyz[ia, :]) + todyn(fixed[ia]))
95+
self._write(fmt.format(*geometry.xyz[ia, :]) + todyn(dynamic[ia]))
9596

9697
@sile_fh_open(True)
9798
def read_supercell(self):
@@ -111,15 +112,15 @@ def read_supercell(self):
111112
return SuperCell(cell)
112113

113114
@sile_fh_open()
114-
def read_geometry(self, ret_fixed=False):
115+
def read_geometry(self, ret_dynamic=False):
115116
r""" Returns Geometry object from the CONTCAR/POSCAR file
116117
117118
Possibly also return the dynamics (if present)
118119
119120
Parameters
120121
----------
121-
ret_fixed : bool, optional
122-
also read selective dynamics (if present), if not, a list of False will be returned
122+
ret_dynamic : bool, optional
123+
also read selective dynamics (if present), if not, a list of True will be returned
123124
"""
124125
sc = self.read_supercell()
125126

@@ -163,15 +164,15 @@ def read_geometry(self, ret_fixed=False):
163164

164165
# Number of atoms
165166
na = len(atom)
166-
# pre-create the fixed list
167-
fixed = [[False] * 3] * na
167+
# pre-create the dynamic list
168+
dynamic = [[False] * 3] * na
168169

169170
xyz = _a.emptyd([na, 3])
170171
for ia in range(na):
171172
line = self.readline().split()
172173
xyz[ia, :] = list(map(float, line[:3]))
173174
if dynamics:
174-
fixed[ia] = list(map(lambda x: x.lower() == 't', line[3:6]))
175+
dynamic[ia] = list(map(lambda x: x.lower() == 't', line[3:6]))
175176

176177
if cart:
177178
# The unit of the coordinates are cartesian
@@ -181,8 +182,8 @@ def read_geometry(self, ret_fixed=False):
181182

182183
# The POT/CONT-CAR does not contain information on the atomic species
183184
geom = Geometry(xyz=xyz, atom=atom, sc=sc)
184-
if ret_fixed:
185-
return geom, np.array(fixed, dtype=np.bool_)
185+
if ret_dynamic:
186+
return geom, np.array(dynamic, dtype=np.bool_)
186187
return geom
187188

188189
def ArgumentParser(self, p=None, *args, **kwargs):

sisl/io/vasp/tests/test_car.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def test_geometry_car_allsame(sisl_tmp):
5151
assert carSileVASP(f).read_geometry() == geom
5252

5353

54-
def test_geometry_car_fixed(sisl_tmp):
55-
f = sisl_tmp('test_fixed.POSCAR', _dir)
54+
def test_geometry_car_dynamic(sisl_tmp):
55+
f = sisl_tmp('test_dynamic.POSCAR', _dir)
5656

5757
atoms = Atom[1]
5858
xyz = np.random.rand(10, 3)
@@ -61,16 +61,16 @@ def test_geometry_car_fixed(sisl_tmp):
6161
read = carSileVASP(f)
6262

6363
geom.write(carSileVASP(f, 'w'))
64-
g, fix = read.read_geometry(ret_fixed=True)
65-
assert not np.any(fix)
66-
67-
geom.write(carSileVASP(f, 'w'), fixed=True)
68-
g, fix = read.read_geometry(ret_fixed=True)
69-
assert np.all(fix)
70-
71-
fixed = [False] * len(geom)
72-
fixed[0] = [True, False, True]
73-
geom.write(carSileVASP(f, 'w'), fixed=fixed)
74-
g, fix = read.read_geometry(ret_fixed=True)
75-
assert np.array_equal(fixed[0], fix[0])
76-
assert not np.any(fix[1:])
64+
g, dyn = read.read_geometry(ret_dynamic=True)
65+
assert np.all(dyn)
66+
67+
geom.write(carSileVASP(f, 'w'), dynamic=False)
68+
g, dyn = read.read_geometry(ret_dynamic=True)
69+
assert not np.any(dyn)
70+
71+
dynamic = [False] * len(geom)
72+
dynamic[0] = [True, False, True]
73+
geom.write(carSileVASP(f, 'w'), dynamic=dynamic)
74+
g, dyn = read.read_geometry(ret_dynamic=True)
75+
assert np.array_equal(dynamic[0], dyn[0])
76+
assert not np.any(dyn[1:])

0 commit comments

Comments
 (0)