Skip to content

[Code scan] Read LATTICE_PARAMETER blocks consistently in STRU parsers #7555

Description

@njzjz

This issue is a result of a Codex global repository scan.

Several Python STRU parsers check for a LATTICE_PARAMETER block but then read blocks['LATTICE_PARAMETERS'] with an extra S. STRU files that use LATTICE_PARAMETER instead of LATTICE_VECTORS therefore raise KeyError instead of being parsed.

ASE interface parser:

stru['lat'] = {'const': float(blocks['LATTICE_CONSTANT'][0])}
if 'LATTICE_VECTORS' in blocks:
stru['lat']['vec'] = [[float(x) for x in line.split()]
for line in blocks['LATTICE_VECTORS']]
elif 'LATTICE_PARAMETER' in blocks:
stru['lat']['param'] = [float(x)
for x in blocks['LATTICE_PARAMETERS'].split()]

Multiwfn interface parser:

stru['lat'] = {'const': float(blocks['LATTICE_CONSTANT'][0])}
if 'LATTICE_VECTORS' in blocks:
stru['lat']['vec'] = [[float(x) for x in line.split()] for line in blocks['LATTICE_VECTORS']]
elif 'LATTICE_PARAMETER' in blocks:
stru['lat']['param'] = [float(x) for x in blocks['LATTICE_PARAMETERS'].split()]

PyABACUS parser:

stru['lat'] = {'const': float(blocks['LATTICE_CONSTANT'][0])}
if 'LATTICE_VECTORS' in blocks:
stru['lat']['vec'] = [[float(x) for x in line.split()]
for line in blocks['LATTICE_VECTORS']]
elif 'LATTICE_PARAMETER' in blocks:
stru['lat']['param'] = [float(x)
for x in blocks['LATTICE_PARAMETERS'].split()]

Relevant pattern:

elif 'LATTICE_PARAMETER' in blocks:
    stru['lat']['param'] = [float(x)
                            for x in blocks['LATTICE_PARAMETERS'].split()]

Suggested fix:

Read from blocks['LATTICE_PARAMETER'] and account for the fact that block values are stored as a list of lines, for example blocks['LATTICE_PARAMETER'][0].split(). Add coverage for STRU files that contain LATTICE_PARAMETER without LATTICE_VECTORS.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions