コード例 #1
0
ファイル: 32rigid_bodies.py プロジェクト: CCBatIIT/AlGDock
def anchor(universe):
	"""Anchor a universe"""
	if(universe.numberOfAtoms() >=3):
		#set anchor atoms indexes	
		a1i	= 0
		for i in range(len(universe.atomList()[a1i].bondedTo())):
			for j in range(len(universe.atomList()[a1i].bondedTo()[i].bondedTo())):
				if universe.atomList()[a1i] is not \
					universe.atomList()[a1i].bondedTo()[i].bondedTo()[j] :
					a2i = i;
					a3i = j;
					break
		print 'anchor using: ', a1i, a2i, a3i
		
		v1 = universe.atomList()[a1i].position();
		v2 = universe.atomList()[a1i].bondedTo()[a2i].position();
		v3 = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position();
	
		vT01 = -v1;
		tra01 = Translation(vT01);
		universe.applyTransformation(tra01);
	
	
		x = universe.atomList()[a1i].bondedTo()[a2i].position().x();
		y = 0;
		z = universe.atomList()[a1i].bondedTo()[a2i].position().z();
		vR01 = Vector(x,y,z);
		vR02 = Vector(1,0,0);
	
		sign = 1.0
		if ((z > 0) and (x > 0)) or ((z < 0) and (x < 0)):
			sign = -1.0
		
		rot01 = Rotation(Vector(0,1,0), sign*vR01.angle(vR02));
		universe.applyTransformation(rot01);
	
		v4 = universe.atomList()[a1i].bondedTo()[a2i].position();
	
		sign = -1.0
		if ((x > 0) and (y > 0)) or ((x < 0) and (y < 0)):
			sign = 1.0
		rot02 = Rotation(Vector(0,0,1), sign*v4.angle(Vector(1,0,0)));
		universe.applyTransformation(rot02);
	
		x = 0;
		y = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position().y();
		z = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position().z();
	
		sign = 1.0
		if ((z > 0) and (y > 0)) or ((z < 0) and (y < 0)):
			sign = -1.0
	
		vR03 = Vector(x,y,z);
		vR04 = Vector(0,1,0);
		rot03 = Rotation(Vector(1,0,0), sign*vR03.angle(vR04));
		universe.applyTransformation(rot03);
	
	else:
		print "Molecule too little to be anchored";
コード例 #2
0
ファイル: findsym.py プロジェクト: yfyh2013/ase
    def __init__(self, atoms, outfile=None):

        unitcell = atoms.get_cell()
        A = Vector(unitcell[0])
        B = Vector(unitcell[1])
        C = Vector(unitcell[2])

        # lengths of the vectors
        a = A.length()  #*angstroms2bohr
        b = B.length()  #*angstroms2bohr
        c = C.length()  #*angstroms2bohr

        # angles between the vectors
        rad2deg = 360. / (2. * math.pi)
        alpha = B.angle(C) * rad2deg
        beta = A.angle(C) * rad2deg
        gamma = A.angle(B) * rad2deg

        scaledpositions = atoms.get_scaled_positions()
        chemicalsymbols = [atom.get_symbol() for atom in atoms]

        input = ''

        input += 'title \n'
        input += '0    tolerance\n'
        input += '2        lattice parameters in lengths and angles\n'
        input += '%1.3f %1.3f %1.3f %1.3f %1.3f %1.3f\n' % (a, b, c, alpha,
                                                            beta, gamma)
        input += '1  3 basis vectors for unit cell\n'

        input += '1.00 0.00 0.00\n'
        input += '0.00 1.00 0.00\n'
        input += '0.00 0.00 1.00\n'

        input += '%i   number of atoms\n' % len(atoms)

        types = ''
        for atom in atoms:
            types += str(atom.get_atomic_number()) + ' '

        input += types + '\n'

        for i, atom in enumerate(atoms):
            input += '%1.3f %1.3f %1.3f\n' % tuple(scaledpositions[i])

        pin, pout = os.popen2('findsym')
        pin.writelines(input)
        pin.close()
        self.output = pout.readlines()
        pout.close()

        if outfile:
            f = open(outfile, 'w')
            f.writelines(self.output)
            f.close()

        if os.path.exists('findsym.log'):
            os.remove('findsym.log')
コード例 #3
0
ファイル: findsym.py プロジェクト: PHOTOX/fuase
    def __init__(self,atoms,outfile=None):
        
        unitcell = atoms.get_cell()
        A = Vector(unitcell[0])
        B = Vector(unitcell[1])
        C = Vector(unitcell[2])

        # lengths of the vectors
        a = A.length()#*angstroms2bohr
        b = B.length()#*angstroms2bohr
        c = C.length()#*angstroms2bohr

        # angles between the vectors
        rad2deg = 360./(2.*math.pi)
        alpha = B.angle(C)*rad2deg
        beta = A.angle(C)*rad2deg
        gamma = A.angle(B)*rad2deg

        scaledpositions = atoms.get_scaled_positions()
        chemicalsymbols = [atom.get_symbol() for atom in atoms]

        input = ''

        input += 'title \n'
        input += '0    tolerance\n'
        input += '2        lattice parameters in lengths and angles\n'
        input += '%1.3f %1.3f %1.3f %1.3f %1.3f %1.3f\n' % (a,b,c,
                                                            alpha,beta,gamma)
        input += '1  3 basis vectors for unit cell\n'

        input += '1.00 0.00 0.00\n'
        input += '0.00 1.00 0.00\n'
        input += '0.00 0.00 1.00\n'

        input += '%i   number of atoms\n' % len(atoms)

        types = ''
        for atom in atoms:
            types += str(atom.get_atomic_number()) + ' '

        input += types + '\n'

        for i,atom in enumerate(atoms):
            input += '%1.3f %1.3f %1.3f\n' % tuple(scaledpositions[i])

        pin,pout = os.popen2('findsym')
        pin.writelines(input)
        pin.close()
        self.output = pout.readlines()
        pout.close()

        if outfile:
            f = open(outfile,'w')
            f.writelines(self.output)
            f.close()

        if os.path.exists('findsym.log'):
            os.remove('findsym.log')
コード例 #4
0
    def __init__(self, atoms, outfile=None):
        '''outfile is where the results will be stored if you want
        them. Otherwise they go into a tempfile that is deleted.'''

        id, infile = tempfile.mkstemp()

        if outfile is None:
            od, ofile = tempfile.mkstemp()
        else:
            ofile = outfile

        unitcell = atoms.get_cell()

        A = Vector(unitcell[0])
        B = Vector(unitcell[1])
        C = Vector(unitcell[2])

        # lengths of the vectors
        a = A.length()  #*angstroms2bohr
        b = B.length()  #*angstroms2bohr
        c = C.length()  #*angstroms2bohr

        # angles between the vectors
        rad2deg = 360. / (2. * math.pi)
        alpha = B.angle(C) * rad2deg
        beta = A.angle(C) * rad2deg
        gamma = A.angle(B) * rad2deg

        scaledpositions = atoms.get_scaled_positions()
        chemicalsymbols = [atom.get_symbol() for atom in atoms]

        f = open(infile, 'w')
        f.write('P\n')

        f.write('%1.4f %1.4f %1.4f %1.4f %1.4f %1.4f\n' %
                (a, b, c, alpha, beta, gamma))

        f.write('%i\n' % len(atoms))

        for i, atom in enumerate(atoms):
            f.write('%1.4f %1.4f %1.4f\n' % tuple(scaledpositions[i]))
            f.write('%s\n\n' % chemicalsymbols[i])
        f.close()

        os.system('sgroup %s %s' % (infile, ofile))

        f = open(ofile, 'r')
        self.output = f.readlines()
        f.close()

        os.unlink(infile)
        os.close(id)

        if outfile is None:
            os.unlink(ofile)
            os.close(od)  # you must close the file descriptor or
コード例 #5
0
ファイル: symmol.py プロジェクト: misdoro/python-ase
    def __init__(self,atoms,outfile=None):
        
        unitcell = atoms.get_cell()
        A = Vector(unitcell[0])
        B = Vector(unitcell[1])
        C = Vector(unitcell[2])

        # lengths of the vectors
        a = A.length()#*angstroms2bohr
        b = B.length()#*angstroms2bohr
        c = C.length()#*angstroms2bohr

        # angles between the vectors
        rad2deg = 360./(2.*math.pi)
        alpha = B.angle(C)*rad2deg
        beta = A.angle(C)*rad2deg
        gamma = A.angle(B)*rad2deg

        scaledpositions = atoms.get_scaled_positions()
        chemicalsymbols = [atom.get_symbol() for atom in atoms]

        input = ''
        input += '%1.3f %1.3f %1.3f %1.3f %1.3f %1.3f\n' % (a,b,c,
                                                            alpha,beta,gamma)
        input += '1 1 0.1 0.1\n' 

        for atom in atoms:
            sym = atom.get_symbol()
            group = 1
            x,y,z = atom.get_position()
            #format(a6,i2,6f9.5)
            input += str(FortranLine((sym,
                                      group,
                                      x,y,z),
                                     FortranFormat('a6,i2,3f9.5')))+'\n'
                    
        pin,pout = os.popen2('symmol')
        pin.writelines(input)
        pin.close()
        self.output = pout.readlines()
        pout.close()

        if outfile:
            f = open(outfile,'w')
            f.writelines(self.output)
            f.close()

        if os.path.exists('symmol.log'):
            os.remove('symmol.log')
コード例 #6
0
ファイル: symmol.py プロジェクト: essil1/ase-laser
    def __init__(self,atoms,outfile=None):

        unitcell = atoms.get_cell()
        A = Vector(unitcell[0])
        B = Vector(unitcell[1])
        C = Vector(unitcell[2])

        # lengths of the vectors
        a = A.length()#*angstroms2bohr
        b = B.length()#*angstroms2bohr
        c = C.length()#*angstroms2bohr

        # angles between the vectors
        rad2deg = 360./(2.*math.pi)
        alpha = B.angle(C)*rad2deg
        beta = A.angle(C)*rad2deg
        gamma = A.angle(B)*rad2deg

        # scaledpositions = atoms.get_scaled_positions()
        # chemicalsymbols = [atom.get_symbol() for atom in atoms]

        input = ''
        input += '%1.3f %1.3f %1.3f %1.3f %1.3f %1.3f\n' % (a,b,c,
                                                            alpha,beta,gamma)
        input += '1 1 0.1 0.1\n'

        for atom in atoms:
            sym = atom.get_symbol()
            group = 1
            x,y,z = atom.get_position()
            #format(a6,i2,6f9.5)
            input += str(FortranLine((sym,
                                      group,
                                      x,y,z),
                                     FortranFormat('a6,i2,3f9.5')))+'\n'

        pin,pout = os.popen2('symmol')
        pin.writelines(input)
        pin.close()
        self.output = pout.readlines()
        pout.close()

        if outfile:
            f = open(outfile,'w')
            f.writelines(self.output)
            f.close()

        if os.path.exists('symmol.log'):
            os.remove('symmol.log')
コード例 #7
0
ファイル: script-237.py プロジェクト: vormar/dft-book
import numpy as np
from Scientific.Geometry import Vector
A = Vector([1,1,1])   #Scientfic
a = np.array([1,1,1]) #numpy
B = Vector([0.0,1.0,0.0])
print '|A| = ',A.length()        #Scientific Python way
print '|a| = ',np.sum(a**2)**0.5 #numpy way
print '|a| = ',np.linalg.norm(a) #numpy way 2
print 'ScientificPython angle = ',A.angle(B) #in radians
print 'numpy angle =            ',np.arccos(np.dot(a/np.linalg.norm(a),B/np.linalg.norm(B)))
#cross products
print 'Scientific A .cross. B = ',A.cross(B)
print 'numpy A .cross. B      = ',np.cross(A,B) #you can use Vectors in numpy
コード例 #8
0
ファイル: jasp_extensions.py プロジェクト: ycstone/jasp
def pretty_print(self):
    '''
    __str__ function to print the calculator with a nice summary, e.g. jaspsum
    '''
    # special case for neb calculations
    if self.int_params['images'] is not None:
        # we have an neb.
        s = []
        s.append(': -----------------------------')
        s.append('  VASP NEB calculation from %s' % os.getcwd())
        try:
            images, energies = self.get_neb()
            for i,e in enumerate(energies):
                s += ['image {0}: {1: 1.3f}'.format(i,e)]
        except (VaspQueued):
            s += ['Job is in queue']
        return '\n'.join(s)

    s = []
    s.append(': -----------------------------')
    s.append('  VASP calculation from %s' % os.getcwd())
    if hasattr(self,'converged'):
        s.append('  converged: %s' % self.converged)

    try:
        atoms = self.get_atoms()

        uc = atoms.get_cell()

        try:
            self.converged = self.read_convergence()
        except IOError:
            # eg no outcar
            self.converged = False

        if not self.converged:
            try:
                print self.read_relaxed()
            except IOError:
                print False
        if self.converged:
            energy = atoms.get_potential_energy()
            forces = atoms.get_forces()
        else:
            energy = np.nan
            forces = [np.array([np.nan, np.nan, np.nan]) for atom in atoms]

        if self.converged:
            if hasattr(self,'stress'):
                stress = self.stress
            else:
                stress = None
        else:
            stress = None

        # get a,b,c,alpha,beta, gamma
        from Scientific.Geometry import Vector
        A = Vector(uc[0,:])
        B = Vector(uc[1,:])
        C = Vector(uc[2,:])
        a = A.length()
        b = B.length()
        c = C.length()
        alpha = B.angle(C)*180/np.pi
        beta = A.angle(C)*180/np.pi
        gamma = B.angle(C)*180/np.pi
        volume = atoms.get_volume()

        s.append('  Energy = %f eV' % energy)
        s.append('\n  Unit cell vectors (angstroms)')
        s.append('        x       y     z      length')
        s.append('  a0 [% 3.3f % 3.3f % 3.3f] %3.3f' % (uc[0][0],
                                                     uc[0][1],
                                                     uc[0][2],
                                                     A.length()))
        s.append('  a1 [% 3.3f % 3.3f % 3.3f] %3.3f' % (uc[1][0],
                                                     uc[1][1],
                                                     uc[1][2],
                                                     B.length()))
        s.append('  a2 [% 3.3f % 3.3f % 3.3f] %3.3f' % (uc[2][0],
                                                     uc[2][1],
                                                     uc[2][2],
                                                     C.length()))
        s.append('  a,b,c,alpha,beta,gamma (deg): %1.3f %1.3f %1.3f %1.1f %1.1f %1.1f' % (a,
                                                                                  b,
                                                                                  c,
                                                                                  alpha,
                                                                                  beta,gamma))
        s.append('  Unit cell volume = {0:1.3f} Ang^3'.format(volume))

        if stress is not None:
            s.append('  Stress (GPa):xx,   yy,    zz,    yz,    xz,    xy')
            s.append('            % 1.3f % 1.3f % 1.3f % 1.3f % 1.3f % 1.3f' % tuple(stress))
        else:
            s += ['  Stress was not computed']

        constraints = None
        if hasattr(atoms, 'constraints'):
            from ase.constraints import FixAtoms, FixScaled
            constraints = [[None, None, None] for atom in atoms]
            for constraint in atoms.constraints:
                if isinstance(constraint, FixAtoms):
                    for i, constrained in  enumerate(constraint.index):
                        if constrained:
                            constraints[i] = [True, True, True]
                if isinstance(constraint, FixScaled):
                    constraints[constraint.a] = constraint.mask.tolist()

        if constraints is None:
            s.append(' Atom#  sym       position [x,y,z]         tag  rmsForce')
        else:
            s.append(' Atom#  sym       position [x,y,z]         tag  rmsForce constraints')

        for i,atom in enumerate(atoms):
            rms_f = np.sum(forces[i]**2)**0.5
            ts = '  {0:^4d} {1:^4s} [{2:<9.3f}{3:^9.3f}{4:9.3f}] {5:^6d}{6:1.2f}'.format(i,
                                                           atom.symbol,
                                                           atom.x,
                                                           atom.y,
                                                           atom.z,
                                                           atom.tag,
                                                           rms_f)
            # VASP has the opposite convention of constrained
            # Think: F = frozen
            if constraints is not None:
                ts += '      {0} {1} {2}'.format('F' if constraints[i][0] is True else 'T',
                                                 'F' if constraints[i][1] is True else 'T',
                                                 'F' if constraints[i][2] is True else 'T')

            s.append(ts)

        s.append('--------------------------------------------------')
        if self.get_spin_polarized() and self.converged:
            s.append('Spin polarized: Magnetic moment = %1.2f' % self.get_magnetic_moment(atoms))

    except AttributeError:
        # no atoms
        pass

    if os.path.exists('INCAR'):
        # print all parameters that are set
        self.read_incar()
        ppp_list = self.get_pseudopotentials()
    else:
        ppp_list=[(None, None, None)]
    s += ['\nINCAR Parameters:']
    s += ['-----------------']
    for d in [self.int_params,
              self.float_params,
              self.exp_params,
              self.bool_params,
              self.list_params,
              self.dict_params,
              self.string_params,
              self.special_params,
              self.input_params]:

        for key in d:
            if key is 'magmom':
                np.set_printoptions(precision=3)
                value = textwrap.fill(str(d[key]),
                                      width=56,
                                      subsequent_indent=' '*17)
                s.append('  %12s: %s' % (key, value))
            elif d[key] is not None:
                value = textwrap.fill(str(d[key]),
                                      width=56,
                                      subsequent_indent=' '*17)
                s.append('  %12s: %s' % (key, value))

    s += ['\nPseudopotentials used:']
    s += ['----------------------']

    for sym,ppp,hash in ppp_list:
        s += ['{0}: {1} (git-hash: {2})'.format(sym,ppp,hash)]

    #  if ibrion in [5,6,7,8] print frequencies
    if self.int_params['ibrion'] in [5,6,7,8]:
        freq,modes = self.get_vibrational_modes()
        s += ['\nVibrational frequencies']
        s += ['mode   frequency']
        s += ['------------------']
        for i,f in enumerate(freq):

            if isinstance(f, float):
                s +=  ['{0:4d}{1: 10.3f} eV'.format(i,f)]
            elif isinstance(f, complex):
                s +=  ['{0:4d}{1: 10.3f} eV'.format(i,-f.real)]
    return '\n'.join(s)
コード例 #9
0
ファイル: 32rigid_bodies.py プロジェクト: tiendott/AlGDock
def anchor(universe):
    """Anchor a universe"""
    if (universe.numberOfAtoms() >= 3):
        #set anchor atoms indexes
        a1i = 0
        for i in range(len(universe.atomList()[a1i].bondedTo())):
            for j in range(
                    len(universe.atomList()[a1i].bondedTo()[i].bondedTo())):
                if universe.atomList()[a1i] is not \
                 universe.atomList()[a1i].bondedTo()[i].bondedTo()[j] :
                    a2i = i
                    a3i = j
                    break
        print 'anchor using: ', a1i, a2i, a3i

        v1 = universe.atomList()[a1i].position()
        v2 = universe.atomList()[a1i].bondedTo()[a2i].position()
        v3 = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position(
        )

        vT01 = -v1
        tra01 = Translation(vT01)
        universe.applyTransformation(tra01)

        x = universe.atomList()[a1i].bondedTo()[a2i].position().x()
        y = 0
        z = universe.atomList()[a1i].bondedTo()[a2i].position().z()
        vR01 = Vector(x, y, z)
        vR02 = Vector(1, 0, 0)

        sign = 1.0
        if ((z > 0) and (x > 0)) or ((z < 0) and (x < 0)):
            sign = -1.0

        rot01 = Rotation(Vector(0, 1, 0), sign * vR01.angle(vR02))
        universe.applyTransformation(rot01)

        v4 = universe.atomList()[a1i].bondedTo()[a2i].position()

        sign = -1.0
        if ((x > 0) and (y > 0)) or ((x < 0) and (y < 0)):
            sign = 1.0
        rot02 = Rotation(Vector(0, 0, 1), sign * v4.angle(Vector(1, 0, 0)))
        universe.applyTransformation(rot02)

        x = 0
        y = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position(
        ).y()
        z = universe.atomList()[a1i].bondedTo()[a2i].bondedTo()[a3i].position(
        ).z()

        sign = 1.0
        if ((z > 0) and (y > 0)) or ((z < 0) and (y < 0)):
            sign = -1.0

        vR03 = Vector(x, y, z)
        vR04 = Vector(0, 1, 0)
        rot03 = Rotation(Vector(1, 0, 0), sign * vR03.angle(vR04))
        universe.applyTransformation(rot03)

    else:
        print "Molecule too little to be anchored"
コード例 #10
0
ファイル: spin.py プロジェクト: le0ra/eplusinterface_diagrams
"""testing to see in what order the points in sketchup are given
Results: Right hand corkscrew in the direction of the normal"""

from Scientific.Geometry import Vector
import readsketchup
import geometry

txt = open('e.txt', 'r').read()
dct = readsketchup.readsketchup(txt)
for key in dct.keys():
    plane = dct[key]['points']
    normal = Vector(dct[key]['normal'])
    calcnormal = geometry.facenormal(plane)
    # print normal
    # print calcnormal
    print normal.angle(calcnormal)
    print
    
コード例 #11
0
ファイル: atat2excel.py プロジェクト: jkitchin/python-atat
            magmom = atoms.get_magnetic_moment()
            # now we want to write out a row of
            data = [id1, composition, spacegroup, natoms, formation_energy, B, magmom]
            for i, d in enumerate(data):
                sh0.write(NROWS0, i, d)

            # now for sheet 1 - unit cell parameters
            uc = atoms.get_cell()
            A = Vector(uc[0, :])
            B = Vector(uc[1, :])
            C = Vector(uc[2, :])
            a = A.length()
            b = B.length()
            c = C.length()
            alpha = B.angle(C) * 180.0 / np.pi
            beta = A.angle(C) * 180.0 / np.pi
            gamma = B.angle(C) * 180.0 / np.pi
            volume = atoms.get_volume()

            stress = atoms.get_stress()
            if stress is not None:
                sxx, syy, szz, sxy, syz, sxz = stress
            else:
                sxx, syy, szz, sxy, syz, sxz = [None, None, None, None, None, None]

            data = [id1, a, b, c, alpha, beta, gamma, volume, sxx, syy, szz, sxy, syz, sxz]
            for i, d in enumerate(data):
                sh1.write(NROWS1, i, d)

            # now we write each position out.
コード例 #12
0
            data = [
                id1, composition, spacegroup, natoms, formation_energy, B,
                magmom
            ]
            for i, d in enumerate(data):
                sh0.write(NROWS0, i, d)

            # now for sheet 1 - unit cell parameters
            uc = atoms.get_cell()
            A = Vector(uc[0, :])
            B = Vector(uc[1, :])
            C = Vector(uc[2, :])
            a = A.length()
            b = B.length()
            c = C.length()
            alpha = B.angle(C) * 180. / np.pi
            beta = A.angle(C) * 180. / np.pi
            gamma = B.angle(C) * 180. / np.pi
            volume = atoms.get_volume()

            stress = atoms.get_stress()
            if stress is not None:
                sxx, syy, szz, sxy, syz, sxz = stress
            else:
                sxx, syy, szz, sxy, syz, sxz = [
                    None, None, None, None, None, None
                ]

            data = [
                id1, a, b, c, alpha, beta, gamma, volume, sxx, syy, szz, sxy,
                syz, sxz
コード例 #13
0
ファイル: script-274.py プロジェクト: alejandrogallo/dft-book
formulas for computing the d-spacing with sin and cos, vector lengths,
and angles. Below we compute these and use them in the general
triclinic structure formula which applies to all the structures.
'''
from Scientific.Geometry import Vector
import math
unitcell = ag.get_cell()
A = Vector(unitcell[0])
B = Vector(unitcell[1])
C = Vector(unitcell[2])
# lengths of the vectors
a = A.length()#*angstroms2bohr
b = B.length()#*angstroms2bohr
c = C.length()#*angstroms2bohr
# angles between the vectors in radians
alpha = B.angle(C)
beta = A.angle(C)
gamma = A.angle(B)
print('')
print('a   b   c   alpha beta gamma')
print('{0:1.3f} {1:1.3f} {2:1.3f} {3:1.3f} {4:1.3f} {5:1.3f}\n'.format(a,b,c,                                                                alpha,beta,gamma))
h, k, l = (1, 1, 1)
from math import sin, cos
id2 = ((h**2 / a**2 * sin(alpha)**2
       + k**2 / b**2 * sin(beta)**2
       + l**2 / c**2 * sin(gamma)**2
       + 2 * k * l / b / c * (cos(beta) * cos(gamma) - cos(alpha))
       + 2 * h * l / a / c * (cos(alpha) * cos(gamma) - cos(beta))
       + 2 * h * k / a / b * (cos(alpha) * cos(beta) - cos(gamma)))
       / (1 - cos(alpha)**2 - cos(beta)**2 - cos(gamma)**2
         + 2 * cos(alpha) * cos(beta) * cos(gamma)))
コード例 #14
0
ファイル: script-239.py プロジェクト: vormar/dft-book
formulas for computing the d-spacing with sin and cos, vector lengths,
and angles. Below we compute these and use them in the general
triclinic structure formula which applies to all the structures.
'''
from Scientific.Geometry import Vector
import math
unitcell = ag.get_cell()
A = Vector(unitcell[0])
B = Vector(unitcell[1])
C = Vector(unitcell[2])
# lengths of the vectors
a = A.length()  #*angstroms2bohr
b = B.length()  #*angstroms2bohr
c = C.length()  #*angstroms2bohr
# angles between the vectors in radians
alpha = B.angle(C)
beta = A.angle(C)
gamma = A.angle(B)
print
print 'a   b   c   alpha beta gamma'
print '{0:1.3f} {1:1.3f} {2:1.3f} {3:1.3f} {4:1.3f} {5:1.3f}\n'.format(
    a, b, c, alpha, beta, gamma)
h, k, l = (1, 1, 1)
from math import sin, cos
id2 = ((h**2 / a**2 * sin(alpha)**2 + k**2 / b**2 * sin(beta)**2 +
        l**2 / c**2 * sin(gamma)**2 + 2 * k * l / b / c *
        (cos(beta) * cos(gamma) - cos(alpha)) + 2 * h * l / a / c *
        (cos(alpha) * cos(gamma) - cos(beta)) + 2 * h * k / a / b *
        (cos(alpha) * cos(beta) - cos(gamma))) /
       (1 - cos(alpha)**2 - cos(beta)**2 - cos(gamma)**2 +
        2 * cos(alpha) * cos(beta) * cos(gamma)))
コード例 #15
0
ファイル: atat2excel.py プロジェクト: biliu/python-atat
            magmom = atoms.get_magnetic_moment()
            # now we want to write out a row of
            data = [id1, composition, spacegroup, natoms, formation_energy, B, magmom]
            for i,d in enumerate(data):
                sh0.write(NROWS0, i, d)

            # now for sheet 1 - unit cell parameters
            uc = atoms.get_cell()
            A = Vector(uc[0,:])
            B = Vector(uc[1,:])
            C = Vector(uc[2,:])
            a = A.length()
            b = B.length()
            c = C.length()
            alpha = B.angle(C)*180./np.pi
            beta = A.angle(C)*180./np.pi
            gamma = B.angle(C)*180./np.pi
            volume = atoms.get_volume()

            stress = atoms.get_stress()
            if stress is not None:
                sxx, syy, szz, sxy, syz, sxz = stress
            else:
                sxx, syy, szz, sxy, syz, sxz = [None, None, None, None, None, None]

            data = [id1, a, b, c, alpha, beta, gamma, volume, sxx, syy, szz, sxy, syz, sxz]
            for i, d in enumerate(data):
                sh1.write(NROWS1, i, d)

            # now we write each position out.