Révision 5 ase/calculators/turbomole.py
turbomole.py (revision 5) | ||
---|---|---|
1 | 1 |
"""This module defines an ASE interface to Turbomole |
2 |
|
|
3 | 2 |
http://www.turbomole.com/ |
4 | 3 |
""" |
5 | 4 |
import os, sys, string |
... | ... | |
11 | 10 |
import numpy as np |
12 | 11 |
|
13 | 12 |
class Turbomole(Calculator): |
14 |
"""Class for doing Turbomole calculations. |
|
15 |
""" |
|
16 | 13 |
def __init__(self, label='turbomole', calculate_energy="dscf", calculate_forces="grad", post_HF = False): |
17 |
"""Construct TURBOMOLE-calculator object. |
|
18 |
|
|
19 |
Parameters |
|
20 |
========== |
|
21 |
label: str |
|
22 |
Prefix to use for filenames (label.txt, ...). |
|
23 |
Default is 'turbomole'. |
|
24 |
|
|
25 |
Examples |
|
26 |
======== |
|
27 |
This is poor man's version of ASE-Turbomole: |
|
28 |
|
|
29 |
First you do a normal turbomole preparation using turbomole's |
|
30 |
define-program for the initial and final states. |
|
31 |
|
|
32 |
(for instance in subdirectories Initial and Final) |
|
33 |
|
|
34 |
Then relax the initial and final coordinates with desired constraints |
|
35 |
using standard turbomole. |
|
36 |
|
|
37 |
Copy the relaxed initial and final coordinates |
|
38 |
(initial.coord and final.coord) |
|
39 |
and the turbomole related files (from the subdirectory Initial) |
|
40 |
control, coord, alpha, beta, mos, basis, auxbasis etc to the directory |
|
41 |
you do the diffusion run. |
|
42 |
|
|
43 |
For instance: |
|
44 |
cd $My_Turbomole_diffusion_directory |
|
45 |
cd Initial; cp control alpha beta mos basis auxbasis ../; |
|
46 |
cp coord ../initial.coord; |
|
47 |
cd ../; |
|
48 |
cp Final/coord ./final.coord; |
|
49 |
mkdir Gz ; cp * Gz ; gzip -r Gz |
|
50 |
|
|
51 |
from ase.io import read |
|
52 |
from ase.calculators.turbomole import Turbomole |
|
53 |
a = read('coord', index=-1, format='turbomole') |
|
54 |
calc = Turbomole() |
|
55 |
a.set_calculator(calc) |
|
56 |
e = a.get_potential_energy() |
|
57 |
|
|
58 |
""" |
|
59 |
|
|
60 | 14 |
self.label = label |
61 | 15 |
self.converged = False |
62 | 16 |
|
... | ... | |
88 | 42 |
def execute(self, command): |
89 | 43 |
from subprocess import Popen, PIPE |
90 | 44 |
try: |
45 |
# the sub process gets started here |
|
91 | 46 |
proc = Popen([command], shell=True, stderr=PIPE) |
92 | 47 |
error = proc.communicate()[1] |
93 |
if "abnormally" in error: |
|
48 |
# check the error output |
|
49 |
if not " ended normally" in error: |
|
94 | 50 |
raise OSError(error) |
95 | 51 |
print "TM command: ", command, "successfully executed" |
96 | 52 |
except OSError, e: |
97 |
print >>sys.stderr, "Execution failed:", e |
|
53 |
print >>sys.stderr, "Execution failed: ", e
|
|
98 | 54 |
sys.exit(1) |
99 | 55 |
|
100 | 56 |
def get_potential_energy(self, atoms): |
... | ... | |
134 | 90 |
return self.forces.copy() |
135 | 91 |
|
136 | 92 |
def get_stress(self, atoms): |
137 |
return self.stress.copy()
|
|
93 |
return self.stress |
|
138 | 94 |
|
139 | 95 |
def set_atoms(self, atoms): |
140 | 96 |
if self.atoms == atoms: |
... | ... | |
162 | 118 |
energy_tmp = float(line.split()[1]) |
163 | 119 |
if self.post_HF: |
164 | 120 |
energy_tmp += float(line.split()[4]) |
121 |
# update energy units |
|
165 | 122 |
self.e_total = energy_tmp * Hartree |
166 | 123 |
|
167 | 124 |
|
... | ... | |
184 | 141 |
print 'Gradients not found' |
185 | 142 |
raise RuntimeError("Please check TURBOMOLE gradients") |
186 | 143 |
|
144 |
# next line |
|
187 | 145 |
iline += len(self.atoms) + 1 |
146 |
# $end line |
|
188 | 147 |
nline -= 1 |
148 |
# read gradients |
|
189 | 149 |
for i in xrange(iline, nline): |
190 | 150 |
line = string.replace(lines[i],'D','E') |
191 | 151 |
#tmp=np.append(forces_tmp,np.array\ |
Formats disponibles : Unified diff