Esempio n. 1
0
    def bond_length_types(self, a1, a2, lb, ub):
        """bond_length_types(a1, a2, lb, ub) --> get all a1-a2 distances.

        a1     -- symbol of the first element in pair or "ALL"
        a2     -- symbol of the second element in pair or "ALL"
        lb     -- lower bond length boundary
        ub     -- upper bond length boundary

        Return a dictionary of distance data containing

        dij  : list of bond lenghts within given bounds
        ddij : list of bond legnth standard deviations
        ij0  : pairs of atom indices starting from 0
        ij1  : pairs of atom indices starting from 1

        Raises: ValueError if selected atom(s) does not exist
                pdffit.unassignedError when no structure has been loaded.
        """
        rv = pdffit2.bond_length_types(self._handle, a1, a2, lb, ub)
        return rv
Esempio n. 2
0
    def bond_length_types(self, a1, a2, lb, ub):
        """bond_length_types(a1, a2, lb, ub) --> get all a1-a2 distances.

        a1     -- symbol of the first element in pair or "ALL"
        a2     -- symbol of the second element in pair or "ALL"
        lb     -- lower bond length boundary
        ub     -- upper bond length boundary

        Return a dictionary of distance data containing

        dij  : list of bond lenghts within given bounds
        ddij : list of bond legnth standard deviations
        ij0  : pairs of atom indices starting from 0
        ij1  : pairs of atom indices starting from 1

        Raises: ValueError if selected atom(s) does not exist
                pdffit.unassignedError when no structure has been loaded.
        """
        rv = pdffit2.bond_length_types(self._handle, a1, a2, lb, ub)
        return rv
Esempio n. 3
0
    def blen(self, *args):
        """blen(i, j) --> Show bond length defined by atoms i and j.

        i      -- index of the first atom starting at 1
        j      -- index of the second atom starting at 1

        No return value.  Use bond_length_atoms() to retrieve result.

        Second form:

        blen(a1, a2, lb, ub) --> Show sorted lengths of all a1-a2 bonds.

        a1     -- symbol of the first element in pair or "ALL"
        a2     -- symbol of the second element in pair or "ALL"
        lb     -- lower bond length boundary
        ub     -- upper bond length boundary

        No return value.  Use bond_length_types() to retrieve results.

        Raises: ValueError if selected atom(s) does not exist
                pdffit.unassignedError when no structure has been loaded
        """
        # first form
        if len(args)==2:
            dij, ddij = self.bond_length_atoms(*args[0:2])
            atom_symbols = self.get_atoms()
            ij = (args[0], args[1])
            # check ij
            if min(ij) - 1 < 0 or max(ij) - 1 >= len(atom_symbols):
                emsg = "Incorrect atom number(s): %i, %j" % ij
                raise ValueError, emsg
            symij = ( atom_symbols[ij[0] - 1].upper(),
                      atom_symbols[ij[1] - 1].upper() )
            print >> output.stdout, _format_bond_length(dij, ddij, ij, symij)
        # second form
        elif len(args)==4:
            a1, a2, lb, ub = args
            try:
                atom_types = self.get_atom_types()
                if type(a1) is types.IntType:   a1 = atom_types[a1 - 1]
                if type(a2) is types.IntType:   a2 = atom_types[a2 - 1]
            except IndexError:
                # index of non-existant atom type
                return
            # arguments are OK here, get bond length dictionary
            bld = pdffit2.bond_length_types(self._handle, a1, a2, lb, ub)
            s = "(%s,%s) bond lengths in [%gA,%gA] for current phase :" % \
                    (a1, a2, lb, ub)
            print >> output.stdout, s
            atom_symbols = self.get_atoms()
            npts = len(bld['dij'])
            for idx in range(npts):
                dij = bld['dij'][idx]
                ddij = bld['ddij'][idx]
                ij0 = bld['ij0'][idx]
                ij1 = bld['ij1'][idx]
                symij = (atom_symbols[ij0[0]], atom_symbols[ij0[1]])
                s = _format_bond_length(dij, ddij, ij1, symij)
                print >> output.stdout, s
            print >> output.stdout
            if not bld['dij']:
                print >> output.stdout, "   *** No pairs found ***"
        else:
            emsg = "blen() takes 2 or 4 arguments (%i given)" % len(args)
            raise TypeError, emsg
        # done
        return
Esempio n. 4
0
    def blen(self, *args):
        """blen(i, j) --> Show bond length defined by atoms i and j.

        i      -- index of the first atom starting at 1
        j      -- index of the second atom starting at 1

        No return value.  Use bond_length_atoms() to retrieve result.

        Second form:

        blen(a1, a2, lb, ub) --> Show sorted lengths of all a1-a2 bonds.

        a1     -- symbol of the first element in pair or "ALL"
        a2     -- symbol of the second element in pair or "ALL"
        lb     -- lower bond length boundary
        ub     -- upper bond length boundary

        No return value.  Use bond_length_types() to retrieve results.

        Raises: ValueError if selected atom(s) does not exist
                pdffit.unassignedError when no structure has been loaded
        """
        # first form
        if len(args)==2:
            dij, ddij = self.bond_length_atoms(*args[0:2])
            atom_symbols = self.get_atoms()
            ij = (args[0], args[1])
            # indices were already checked in bond_length_atoms call
            assert (0 <= min(ij) - 1) and (max(ij) - 1 < len(atom_symbols))
            symij = ( atom_symbols[ij[0] - 1].upper(),
                      atom_symbols[ij[1] - 1].upper() )
            print(_format_bond_length(dij, ddij, ij, symij), file=output.stdout)
        # second form
        elif len(args)==4:
            a1, a2, lb, ub = args
            try:
                atom_types = self.get_atom_types()
                if isinstance(a1, numbers.Integral):   a1 = atom_types[a1 - 1]
                if isinstance(a2, numbers.Integral):   a2 = atom_types[a2 - 1]
            except IndexError:
                # index of non-existant atom type
                return
            # arguments are OK here, get bond length dictionary
            bld = pdffit2.bond_length_types(self._handle, a1, a2, lb, ub)
            s = "(%s,%s) bond lengths in [%gA,%gA] for current phase :" % \
                    (a1, a2, lb, ub)
            print(s, file=output.stdout)
            atom_symbols = self.get_atoms()
            npts = len(bld['dij'])
            for idx in range(npts):
                dij = bld['dij'][idx]
                ddij = bld['ddij'][idx]
                ij0 = bld['ij0'][idx]
                ij1 = bld['ij1'][idx]
                symij = (atom_symbols[ij0[0]], atom_symbols[ij0[1]])
                s = _format_bond_length(dij, ddij, ij1, symij)
                print(s, file=output.stdout)
            print(file=output.stdout)
            if not bld['dij']:
                print("   *** No pairs found ***", file=output.stdout)
        else:
            emsg = "blen() takes 2 or 4 arguments (%i given)" % len(args)
            raise TypeError(emsg)
        # done
        return