Skip to content

MAINT: Add `write_castep_geom` and `write_castep_md` etc.

Yuji Ikeda requested to merge yuzie007/ase:write-castep-geom-md into master

Checklist

Related to #999

read_castep_geom and read_castep_md are parsers for .geom and .md files created in the CASTEP GeometryOptimisation and MolecularDynamics tasks, respectively. (.ts file for TransitionStateSearch also has a similar format.) These files are in a very similar format; for example, a .geom file is like (full sample outputs are also attached castep.zip)

 BEGIN header

 END header

                                      0                                     F   F   F   F            <-- c
                     -4.8547789339394257E+001   -4.8547789339394257E+001                             <-- E
                      1.0261212851071701E+001    0.0000000000000000E+000    0.0000000000000000E+000  <-- h
                      0.0000000000000000E+000    1.0261212851071701E+001    0.0000000000000000E+000  <-- h
                      0.0000000000000000E+000    0.0000000000000000E+000    1.0261212851071701E+001  <-- h
                     -1.9260897018824800E-004   -9.8899587907200627E-005    9.4888081070416280E-005  <-- S
                     -9.8899587907200627E-005   -2.1123116089299539E-004    5.3168604876770067E-005  <-- S
                      9.4888081070416280E-005    5.3168604876770067E-005   -1.8342555831865330E-004  <-- S
 Al              1    2.8531141705684364E+000    2.5210552755841600E+000    2.5210571653102845E+000  <-- R
 Al              2    2.6678321933292044E+000    7.6083359502845562E+000    7.6078994235500081E+000  <-- R
 Al              3    7.5896522281006611E+000    2.3739060817927697E+000    7.7552942817374664E+000  <-- R
 Al              4    7.6532434018854500E+000    7.7086709588163513E+000    2.2960644833100172E+000  <-- R
 P               1    9.3864586284637647E-002   -2.6127353384699327E-002    1.2239567129853830E-001  <-- R
 P               2    2.9842743916281661E-001    5.2756296774382072E+000    5.0418894532118612E+000  <-- R
 P               3    5.1763302388221364E+000   -3.6155751977345235E-001    4.8046437870262633E+000  <-- R
 P               4    4.9590155140620000E+000    4.8637204051018070E+000    2.7696770930337455E-001  <-- R
 Al              1   -5.8785761480407712E-002   -3.4487843560932291E-002    5.0888063938854561E-002  <-- F
 Al              2   -1.5128507116508151E-003    8.0242371524276990E-003    2.2233202928871335E-002  <-- F
 Al              3    1.6160584446081677E-002    1.1097701111710399E-002   -1.5563594451783742E-002  <-- F
 Al              4    2.8713616112707809E-002   -2.8436171333732555E-002    8.0099253211385404E-003  <-- F
 P               1   -3.8954924888825911E-003    8.6888504664651943E-003   -3.4059443015460780E-002  <-- F
 P               2   -3.2614519730457717E-002   -3.6350526801736088E-002    4.0424301512470466E-003  <-- F
 P               3   -6.3341307694851469E-003    2.1028023664922599E-002    3.2369867706333093E-002  <-- F
 P               4    5.8268554622094501E-002    5.0435729300875046E-002   -6.7920452579200055E-002  <-- F
  
...

These methods are so far not well tested. In this MR, I addressed the issue in the following way.

  • Add corresponding writer methods write_castep_geom and write_castep_md
  • Add write-and-read tests for them

I also:

  • Make ase/io/castep directory, and move castep.py to castep/__init__.py (done already in !3309 (merged))
  • Move read_castep_geom and read_castep_md into new ase/io/castep/geom_md_ts.py
  • Refactor read_castep_geom and read_castep_md

Particularly for the refactoring, although it is rather drastic, this was done after adding the tests and confirming they are passed both before and after the refactoring. In this sense, I believe the refactoring is safe.

Notes: for the refactoring,

  • We can reuse many components both in read_castep_geom and read_castep_md.
  • Presently in read_castep_md there is an non-doc-stringed return_scalars option. With this it returns a tuple of a list of atoms together with other information like MD time (here). I think returning a tuple is rather uncommon for ASE readers, and most of the additional information can either be computed from other properties (e.g. temperature <- kinetic energy <- velocities) or can be stored in a different way (e.g. in MD time in atoms.info). I therefore removed this read_scalars option in my MR.
  • I also removed old read_geom and read_md, which are kept just because of backward compatibility.
Edited by Yuji Ikeda

Merge request reports