Esempio n. 1
0
"""
#test_what = "contraforce"

# specify which testfunction == first input argument
try:
    testfun = argv[1]
except IndexError:
    testfun = "zmat"

# The ASE atoms object for calculating the forces
ar4 = Atoms("Ar4")

ar4.set_calculator(LennardJones())

# PES in cartesian coordiantes:
pes = QFunc(ar4, ar4.get_calculator())

# some variables for the starting values
# length
var1 = 1.12246195815

# and angles (in rad)
var3 = 60.0 / 180. * pi
var4 = 70.5287791696 / 180. * pi
var6 = 59.0020784259 / 180. * pi
var7 = 60.4989607871 / 180 * pi
var8 = pi

td_s = var1

def reduce(vec, mask):
Esempio n. 2
0
    def getTrajactory(self, fileobj='result'):
        from ase.atoms import Atoms, Atom
        from ase import units
        from ase.calculators.singlepoint import SinglePointCalculator
        """Reads quantum espresso output text files."""

        fileobj = open(fileobj, 'rU')
        lines = fileobj.readlines()
        #print lines
        images = []
        lattice = self.getLattices()

        for number, line in enumerate(lines):
            if 'number of atoms/cell' in line:
                numAtom = int(line.split()[-1])
            if 'number of atomic types' in line:
                numElement = int(line.split()[-1])

            if "atomic species   valence    mass" in line:
                elementLines = lines[number + 1:number + 1 + numElement]
                elementsInfo = [[(i) for i in l.split()] for l in elementLines]

                #print numAtom
            if 'lattice parameter (alat)' in line:
                line = line.strip().split('=')[1].strip().split()[0]
                lattice_parameter = float(line) * units.Bohr

            if "crystal axes: (cart. coord. in units of alat)" in line:
                ca_line_no = number
                cell = np.zeros((3, 3))
                for number, line in enumerate(lines[ca_line_no + 1:ca_line_no +
                                                    4]):
                    line = line.split('=')[1].strip()[1:-1]
                    values = [float(value) for value in line.split()]
                    cell[number, 0] = values[0]
                    cell[number, 1] = values[1]
                    cell[number, 2] = values[2]
                cell *= lattice_parameter

            if "site n.     atom                  positions (alat units)" in line:
                initPositionLines = lines[number + 1:number + 1 + numAtom]
                elements = np.array([l.split()[1] for l in initPositionLines])
                scaledPositions = np.array([[float(i) for i in l.split()[6:9]]
                                            for l in initPositionLines])
                atom = Atoms(symbols=elements,
                             scaled_positions=scaledPositions,
                             cell=cell,
                             pbc=True)
                images.append(atom)

            cellkey = 'CELL_PARAMETERS (angstrom)'
            if cellkey in line:
                ca_line_no = number
                cell = np.array([[float(num) for num in line.split()]
                                 for line in lines[ca_line_no + 1:ca_line_no +
                                                   4]])
#        for number, line in enumerate(lines[ca_line_no + 1: ca_line_no + 4]):
#            line = line.split('=')[1].strip()[1:-1]
#            values = [float(value) for value in line.split()]
#            cell[number, 0] = values[0]
#            cell[number, 1] = values[1]
#            cell[number, 2] = values[2]

            posikey = 'ATOMIC_POSITIONS'
            if posikey in line:
                positionLines = lines[number + 1:number + 1 + numAtom]
                elements = np.array([l.split()[0] for l in positionLines])
                positions = np.array([[float(i) for i in l.split()[1:]]
                                      for l in positionLines])
                if 'angstrom' in line:
                    atom = Atoms(symbols=elements,
                                 positions=positions,
                                 cell=cell,
                                 pbc=True)
                elif 'crystal' in line:
                    atom = Atoms(symbols=elements,
                                 scaled_positions=positions,
                                 cell=cell,
                                 pbc=True)
                images.append(atom)

            if "Forces acting on atoms (cartesian axes, Ry/au):" in line:
                #print number
                atom = images[-1]
                forceLines = lines[number + 2:number + 2 + numAtom]
                forces = np.array([[float(i) for i in l.split()[-3:]]
                                   for l in forceLines])
                forces *= units.Ry / units.Bohr
                calc = SinglePointCalculator(atom, forces=forces)
                atom.set_calculator(calc)

            if "total   stress" in line:
                #print number
                atom = images[-1]
                selectLines = lines[number + 1:number + 4]
                selectPrperties = np.array([[float(i) for i in l.split()[-3:]]
                                            for l in selectLines])
                #forces *= units.Ry / units.Bohr
                calc = atom.get_calculator()
                #print(selectPrperties)
                calc.results['stress'] = selectPrperties
                #atom.set_calculator(calc)

        filename = 'Trajectory'
        from ase.io import write
        if len(images) > 1:
            write(filename, images[1:], 'traj')
        else:
            write(filename, images, 'traj')

        from ase.io.trajectory import Trajectory

        traj = Trajectory(filename)
        return traj
Esempio n. 3
0
# Atoms object needs to have all these in order to be able to run correctly:
PdH.set_calculator(calculator)
PdH.set_pbc(True)
sc =  5.59180042562320832916
cell =  [[1.0000000000000000,  0.0000000000000000,  0.0000000000000000],
         [0.5000000000000000,  0.8660254037844386,  0.0000000000000000],
         [0.0000000000000000,  0.0000000000000000,  1.0000000000000000]]
cell = array(cell) * sc
PdH.set_cell(cell)

# Do calculation in Cartesian coordinates
fun1 = Cartesian()

# PES in cartesian coordiantes:
pes = QFunc(PdH, PdH.get_calculator())

def reduce(vec, mask):
    """
    Function for generating starting values.
    Use a mask to reduce the complete vector.
    """
    vec_red = []
    for i, m in enumerate(mask):
         if m:
             vec_red.append(vec[i])
    return array(vec_red)

# The starting geometries in flattened Cartesian coordinates
min1 = array([ 1.3979501064058020,  0.8071068702470560,  1.0232994778890470,
  0.0000000000000000, 0.0000000000000000, 0.0000000000000000,