Ejemplo n.º 1
0
 def __init__(self):
     self._angle_dict = {}
     f = open(context.get_share_filename("toyff_angles.txt"))
     for line in f:
         if line[0] != "#":
             key = tuple(int(word) for word in line[0 : line.index(":")].split(","))
             value = numpy.pi / 180.0 * float(line[line.index(":") + 1 : -1])
             self._angle_dict[key] = value
Ejemplo n.º 2
0
 def __init__(self):
     self.angle_dict = {}
     f = open(context.get_share_filename('toyff_angles.txt'))
     for line in f:
         if line[0] != '#':
             key = tuple(int(word) for word in line[0:line.index(':')].split(","))
             value = numpy.pi/180.0*float(line[line.index(':')+1:-1])
             self.angle_dict[key] = value
Ejemplo n.º 3
0
        pair = frozenset([n1, n2])
        result = None
        for bond_type in bond_types:
            bond_length = self.lengths[bond_type].get(pair)
            if (bond_length is not None) and \
               (distance < bond_length * self.bond_tolerance):
                if result is None:
                    result = bond_type
                    deviation = abs(bond_length - distance)
                else:
                    new_deviation = abs(bond_length - distance)
                    if deviation > new_deviation:
                        result = bond_type
                        deviation = new_deviation
        return result

    def get_length(self, n1, n2, bond_type=BOND_SINGLE):
        """
        Return the length of a bond between n1 and n2 of type bond_type.

        This is a safe method for querying a bond_length. If no answer can be
        found, this get_length returns None.
        """
        dataset = self.lengths.get(bond_type)
        if dataset == None:
            return None
        return dataset.get(frozenset([n1, n2]))


bonds = BondData(context.get_share_filename("bonds.csv"), periodic)
Ejemplo n.º 4
0
                        if word == "NA":
                            atom_info.add_attribute(name, None)
                        else:
                            atom_info.add_attribute(name, convertor(word))
                    self.add_atom_info(atom_info)
                    if self.max_radius < atom_info.radius:
                        self.max_radius = atom_info.radius
                lines_read += 1
        f.close()

    def add_atom_info(self, atom_info):
        self.atoms_by_number[atom_info.number] = atom_info
        self.atoms_by_symbol[atom_info.symbol.lower()] = atom_info

    def __len__(self):
        return len(self.atoms_by_symbol)

    def __getitem__(self, index):
        result = self.atoms_by_number.get(index)
        if (result is None) and isinstance(index, basestring):
            return self.atoms_by_symbol.get(index.lower())
        else:
            return result

    def yield_numbers(self):
        for number in self.atoms_by_number:
            yield number


periodic = PeriodicData(context.get_share_filename("periodic.csv"))
Ejemplo n.º 5
0
            if (bond_length is not None) and \
               (distance < bond_length * self.bond_tolerance):
                if result is None:
                    result = bond_type
                    deviation = abs(bond_length - distance)
                else:
                    new_deviation = abs(bond_length - distance)
                    if deviation > new_deviation:
                        result = bond_type
                        deviation = new_deviation
        return result

    def get_length(self, n1, n2, bond_type=BOND_SINGLE):
        """
        Return the length of a bond between n1 and n2 of type bond_type.

        This is a safe method for querying a bond_length. If no answer can be
        found, this get_length returns None.
        """
        dataset = self.lengths.get(bond_type)
        if dataset == None:
            return None
        return dataset.get(frozenset([n1, n2]))


bonds = BondData(context.get_share_filename("bonds.csv"), periodic)




Ejemplo n.º 6
0
            n_masses[Z+N] = mass

        f = file(filename)
        for i in xrange(39):
            f.next()

        for line in f:
            N = int(line[ 5:10])
            Z = int(line[10:15])
            mass = float(line[96:114].replace(" ", "").replace("#", ""))*1e-6*amu
            add_mass(N, Z, mass)

        f.close()


ame2003 = Ame2003(context.get_share_filename("mass.mas03"))


class NubTab03(object):
    """An interface to a subset of the data that from NubTab03.

       This object contains an attribute abundances. This is a dictionary whose
       keys are the proton numbers (Z) and values are the corresponding values
       are again dictionaries. The latter dictionaries have the mass number (A)
       as keys and the corresponding isotope abundances as values. E.g.
       self.masses[6][12] is the abundance of carbon 12.

       If you use this interface, cite the following reference:

       The NUBASE evaluation of nuclear and decay properties. G. Audi, O. Bersillon,
       J. Blachot and A.H. Wapstra, Nuclear Physics A729, 3-128 (2003)
Ejemplo n.º 7
0
    def _add_atom_info(self, atom_info):
        """Add an atom info object to the database"""
        self.atoms_by_number[atom_info.number] = atom_info
        self.atoms_by_symbol[atom_info.symbol.lower()] = atom_info

    def __len__(self):
        return len(self.atoms_by_symbol)

    def __getitem__(self, index):
        result = self.atoms_by_number.get(index)
        if (result is None) and isinstance(index, basestring):
            return self.atoms_by_symbol.get(index.lower())
        else:
            return result

    def iter_numbers(self):
        """Iterate over all atom numbers in the periodic system

           Usage::

            >>> from molmod.periodic import periodic
            >>> for number in periodic.iter_numbers():
            ...     print number, periodic[number].mass
        """
        for number in sorted(self.atoms_by_number):
            yield number


periodic = PeriodicData(context.get_share_filename("periodic.csv"))