[ase-users] castep interface

Glenn Jones glenn.jones at ucl.ac.uk
Tue Sep 13 13:17:26 CEST 2011


Hi,

I have come across a few problems with the Castep interface - I have tried
to find some solutions and in the end did manage to get the test
castep_interface.py to run. I have yet to try the interface with a full
calculation.

Firstly, I tried to run the castep.py module to create castep_keywords.py,
but came across what are either a couple of bugs or perhaps some
incompatibility in my version of python and the python syntax used. In
order to get keywords to be generated I made the following changes - I
hope the modifications I suggest don't change the intended logic of the
code:

1)

from ..io.castep import write_cell

I changed this to:

from io.castep import write_cell

2)
  File "castep.py", line 736
    constraints = self.atoms.constraints if self.atoms else []
                                          ^
SyntaxError: invalid syntax

I changed this to a long winded way, which I think says what is intended
above:
            if self.atoms:
              constraints = self.atoms.constraints
            else:
              constraints = []

3)
 File "castep.py", line 1026
    interface_options = self._opt if self._export_settings else None
                                   ^
SyntaxError: invalid syntax

likewise, I changed this to:
        if self._export_settings:
          interface_options = self._opt
        else:
          interface_options =None

4)
File "castep.py", line 1881
    opt_castep_command = ''.join(args) if args else ''

Which I changed to:
     if args:
      opt_castep_command = ''.join(args)
    else:
      opt_castep_command =  ''
______________________________________________________

After making the above changes keywords is created with an error, the
following line also appears to need to be changed:

5) CASTEP v5.502, fetched 370 keywords
invalid syntax (castep_keywords.py, line 4)
Ooops, something went wrong with the CASTEP keywords

class Opt():
should perhaps be
class Opt:

by modifying line 1415 to become:
     fh.write('class Opt:\n')
_______________________________________________
I then tried to run castep_interface.py in the tests and came across some
other issues (similar to the above), related to io.castep.py:
6)
 File "<stdin>", line 1, in ?
  File "/home/gjones/ase/ase/io/castep.py", line 197
    icomment = min([line.index(c) if c in line else len(line) for

which I have changed to:
                for c in comment_chars:
                  if c in line:
                    icomment = min(line.index(c))
                  else:
                    icomment = len(line)

(I don't this is quite the same - but it didn't give an error)

7)
File "<stdin>", line 1, in ?
  File "/home/gjones/ase/ase/io/castep.py", line 419
    energy = energy_0K if energy_0K else energy_total

which I have changed to:
            if energy_0K:
              energy = energy_0K
            else:
              energy = energy_total

then castep_interface.py I need to be change:

8)
    __import__(ase_castep_dir + ".io.castep")

I changed to:

    __import__(ase_castep_dir_patched+".io.castep")

9)
Traceback (most recent call last):
  File "castep_interface.py", line 60, in ?
    assert False, 'Could not instantiate castep calculator'
AssertionError: Could not instantiate castep calculator

so before line 60 I added:

from ase.calculators.castep import Castep

Which gave another problem:

10)
 /usr/lib64/openmpi/1.4-gcc/bin/mpirun
/home/gjones/bin/castep-5.5.2c-openmpi
Traceback (most recent call last):
  File "castep_interface.py", line 57, in ?
    c = Castep(directory=tmp_dir, label='test_label')
  File "/home/gjones/ase/ase/calculators/castep.py", line 344, in __init__
    from io.castep import write_cell
ImportError: No module named io.castep
No module named io.castep                      ,

that I resolved by changing line 344 to:
from ase.io.castep import write_cell


___________________________________________________

With the above changes the test ran. However, with the changes I have made
I am not totally confident that I haven't broken anything, or
unnecessarily modified something that could have been done in a more
simple manner.

I have attached my modified files, if they are of any help.

Best regards,

Glenn

-------------- next part --------------
A non-text attachment was scrubbed...
Name: castep_interface.py
Type: text/x-python
Size: 3854 bytes
Desc: not available
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20110913/dabdc15c/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: castep.py
Type: text/x-python
Size: 24077 bytes
Desc: not available
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20110913/dabdc15c/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: castep.py
Type: text/x-python
Size: 76637 bytes
Desc: not available
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20110913/dabdc15c/attachment-0002.py>


More information about the ase-users mailing list