def read_castep_castep(fd, index=None): """ Reads a .castep file and returns an atoms object. The calculator information will be stored in the calc attribute. There is no use of the "index" argument as of now, it is just inserted for convenience to comply with the generic "read()" in ase.io Please note that this routine will return an atom ordering as found within the castep file. This means that the species will be ordered by ascending atomic numbers. The atoms witin a species are ordered as given in the original cell file. Note: This routine returns a single atoms_object only, the last configuration in the file. Yet, if you want to parse an MD run, use the novel function `read_md()` """ from ase.calculators.castep import Castep try: calc = Castep() except Exception as e: # No CASTEP keywords found? warnings.warn( 'WARNING: {0} Using fallback .castep reader...'.format(e)) # Fall back on the old method return read_castep_castep_old(fd, index) calc.read(castep_file=fd) # now we trick the calculator instance such that we can savely extract # energies and forces from this atom. Basically what we do is to trick the # internal routine calculation_required() to always return False such that # we do not need to re-run a CASTEP calculation. # # Probably we can solve this with a flag to the read() routine at some # point, but for the moment I do not want to change too much in there. calc._old_atoms = calc.atoms calc._old_param = calc.param calc._old_cell = calc.cell return [calc.atoms] # Returning in the form of a list for next()
def read_castep_new(filename, index=None): """ This routine is supposed to replace the former read_castep() routine at some point. Basically it does the same job, but it uses the read() functionality from the Castep calculator class. This allows a much more complete parsing and we do not have to take care of syncing the respective routine with each other. Note: This routine returns a single atoms_object only, whereas the former routine, in principle, returned a list of atoms objects. Yet, if you want to parse an MD run, use the novel function `read_md()` There is no use of the "index" argument as of now, it is just inserted for convenience to comply with the generic "read()" in ase.io Please note that this routine will return an atom ordering as found within the castep file. This means that the species will be ordered by ascending atomic numbers. The atoms witin a species are ordered as given in the original cell file. """ from ase.calculators.castep import Castep calc = Castep() calc.read(castep_file=filename) # now we trick the calculator instance such that we can savely extract # energies and forces from this atom. Basically what we do is to trick the # internal routine calculation_required() to always return False such that # we do not need to re-run a CASTEP calculation. # # Probably we can solve this with a flag to the read() routine at some # point, but for the moment I do not want to change too much in there. calc._old_atoms = calc.atoms calc._old_param = calc.param calc._old_cell = calc.cell return calc.atoms