def write_xsf(file_name, atoms): """ For the given AtomsSystem instance, write an .xsf file. Usage: >>> write_xsf(file_name, atoms) """ xsf = open(file_name, 'w') # Molecular structure... if atoms.get_cell() is None: xsf.write('ATOMS\n') i = 0 for atom in atoms._atoms: x,y,z = atom.get_position() info = atomic_number(atom.get_symbol()), x, y, z xsf.write('%2d %12.6f %12.6f %12.6f\n' % info) i += 1 xsf.close() else: xsf.write('CRYSTAL\n') # Primitive lattice vectors (in Angstroms) xsf.write('PRIMVEC\n') va,vb,vc = atoms.get_cell()[0],atoms.get_cell()[1],atoms.get_cell()[2] #va, vb, vc = convert_abc2xyz(cell[0], cell[1], cell[2], # cell[3], cell[4], cell[5]) xsf.write('%12.6f %12.6f %12.6f\n' % tuple(va)) xsf.write('%12.6f %12.6f %12.6f\n' % tuple(vb)) xsf.write('%12.6f %12.6f %12.6f\n' % tuple(vc)) # Conventional lattice vectors (in Angstroms) xsf.write('CONVVEC\n') xsf.write('%12.6f %12.6f %12.6f\n' % tuple(va)) xsf.write('%12.6f %12.6f %12.6f\n' % tuple(vb)) xsf.write('%12.6f %12.6f %12.6f\n' % tuple(vc)) # Atomic coord. in a primitive unit cell (in Angstroms) xsf.write('PRIMCOORD\n') xsf.write('%s 1\n' % str(len(atoms))) i = 0 for atom in atoms._atoms: x,y,z = atom.get_position() info = atomic_number(atom.get_symbol()), x, y, z xsf.write('%2d %12.6f %12.6f %12.6f\n' % info) i += 1 xsf.close()
def set_mass(self, mass): if mass == None: self._mass = float(atomic_weight[atomic_number(self._symbol)]) elif mass < 0: raise ValueError, "Negative mass is not allowed." elif type(mass) != float and type(mass) != int: raise ValueError, "Invaild mass value : %s" % str(mass) else: self._mass = mass
def find_lattice_parameters(symb): info = reference_states[atomic_number(symb)] if info == None: raise ValueError, 'Can`t guess lattice.' lattice = info['symmetry'] # type, lattice constant if lattice == 'fcc' or lattice =='BCC' or lattice == 'Diamond' or lattice == 'Cubic': return lattice, info['a'] # type, length of a, c/a ratio elif lattice == 'hcp' or lattice == 'Tetragonal': return lattice, info['a'], info['c/a'] # type, c/a, length of a, b/a elif lattice == 'Orthorhombic': return lattice, info['c/a'], info['a'], info['b/a'] # type, length of a, alpha elif lattice == 'Rhombohedral': return lattice, info['a'], info['alpha'] # type, interatomic distance elif lattice == 'diatom': return lattice, info['d']