Пример #1
0
def calcfromcif(CIF,
                centres,
                radius,
                allligtypes=[],
                alllignames=[],
                **kwargs):
    """ Main routine for computing ellipsoids from CIF file. """
    # kwargs should be valid arguments for polyhedron.makeellipsoid(), primarily designed for tolerance and maxcycles
    from pieface import readcoords

    logger.debug('Starting file %s', CIF)

    cell, atomcoords, atomtypes, spacegp, symmops, symmid = readcoords.readcif(
        CIF)
    allatoms = readcoords.makeP1cell(atomcoords, symmops, symmid)

    phase = readcoords.Crystal(cell=cell, atoms=allatoms, atomtypes=atomtypes)

    for cen in centres:
        if cen not in list(allatoms.keys()):
            logger.info("Centre %s is not present in atom labels: skipping",
                        cen)
            continue

        validligtyps = list(
            set(allligtypes).intersection(set(atomtypes.values())))
        validlignames = list(
            set(alllignames).intersection(set(atomtypes.keys())))
        if len(validligtyps) == 0 and len(validlignames) == 0:
            raise ValueError(
                "No ligands of type(s) or name(s) '{0}' are present in file {1}. Valid types are {2}"
                .format(", ".join(allligtypes) + ", ".join(alllignames), CIF,
                        ", ".join([str(p) for p in set(atomtypes.values())])))
        elif len(validligtyps) != len(allligtypes):
            logger.info("Not all types %s are present in %s; using %s",
                        ", ".join(allligtypes), CIF, ", ".join(validligtyps))
        elif len(validlignames) != len(alllignames):
            logger.info("Not all labels %s are present in %s; using %s",
                        ", ".join(alllignames), CIF, ", ".join(validlignames))
        # Calculate ligands for current centre: the coordinates returned may be in a different unit cell to those in allatoms
        ligands, ligtypes = readcoords.findligands(cen,
                                                   phase.atoms,
                                                   phase.orthomatrix(),
                                                   radius=radius,
                                                   types=validligtyps,
                                                   names=validlignames,
                                                   atomtypes=phase.atomtypes)

        phase.makepolyhedron({cen: allatoms[cen]},
                             ligands,
                             atomdict=None,
                             ligtypes=ligtypes)

        polynm = cen + "_poly"

        getattr(phase, polynm).makeellipsoid(phase.orthomatrix(), **kwargs)

    logger.debug('Finishing file %s', CIF)

    return phase
Пример #2
0
 def test_read_CIFS(self):
     """ Test CIF reads correctly"""
     for cif in self.CIFS:
         returnvals = readcoords.readcif(self.CIFS[cif])
         self.assertDictEqual(returnvals[0], self.results[cif]['cell'])
         # Test atomcoords are equal
         self.assertItemsEqual(list(returnvals[1].keys()),
                               list(self.results[cif]['atomcoords'].keys()))
         for k in list(returnvals[1].keys()):
             np.testing.assert_array_almost_equal(
                 returnvals[1][k], self.results[cif]['atomcoords'][k])
         self.assertDictEqual(returnvals[2], self.results[cif]['atomtypes'])
         self.assertEqual(returnvals[3], self.results[cif]['spacegrp'])
         self.assertListEqual(returnvals[4], self.results[cif]['symmops'])
         self.assertListEqual(returnvals[5], self.results[cif]['symmid'])
Пример #3
0
    def test_read_internet_CIF(self):
        """ Check that we can read a CIF online from COD (requires an internet connection). """

        ciffile = 'http://www.crystallography.net/cod/1004021.cif'
        cif = '1004021'

        returnvals = readcoords.readcif(ciffile)
        self.assertDictEqual(returnvals[0], self.results[cif]['cell'])
        # Test atomcoords are equal
        self.assertItemsEqual(list(returnvals[1].keys()),
                              list(self.results[cif]['atomcoords'].keys()))
        for k in list(returnvals[1].keys()):
            np.testing.assert_array_almost_equal(
                returnvals[1][k], self.results[cif]['atomcoords'][k])
        self.assertDictEqual(returnvals[2], self.results[cif]['atomtypes'])
        self.assertEqual(returnvals[3], self.results[cif]['spacegrp'])
        self.assertListEqual(returnvals[4], self.results[cif]['symmops'])
        self.assertListEqual(returnvals[5], self.results[cif]['symmid'])
Пример #4
0
def _alltyplbls(CIF):
    """ Return all allowed labels and corresponding types in CIF file. """
    from pieface.readcoords import readcif
    cell, atomcoords, atomtypes, spacegp, symmops, symmid = readcif(CIF)
    # Just return atomtypes dict {label: type} direct from readcif
    return atomtypes
Пример #5
0
def _alllabels(CIF, phase=0):
    """ Return all allowed labels in CIF file. """
    from pieface.readcoords import readcif
    cell, atomcoords, atomtypes, spacegp, symmops, symmid = readcif(CIF, phase)
    return atomcoords.keys()