Пример #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_cellstring(self):
     """ Test intialising with string of lattice parameters """
     self.Crystal = readcoords.Crystal(cell=str(self.cell['a'])+" "+\
                                            str(self.cell['b'])+" "+\
                                            str(self.cell['c'])+" "+\
                                            str(self.cell['alp'])+" "+\
                                            str(self.cell['bet'])+" "+\
                                            str(self.cell['gam']), atoms=None, atomtypes=None)
     self.assertEqual(self.Crystal.cell, self.cell)
Пример #3
0
 def test_celllist(self):
     """ Test intialising with list of lattice parameters """
     self.Crystal = readcoords.Crystal(cell=[
         self.cell['a'], self.cell['b'], self.cell['c'], self.cell['alp'],
         self.cell['bet'], self.cell['gam']
     ],
                                       atoms=None,
                                       atomtypes=None)
     self.assertEqual(self.Crystal.cell, self.cell)
Пример #4
0
 def test_celldict(self):
     """ Test intialising with dictionary of lattice parameters """
     self.Crystal = readcoords.Crystal(cell=self.cell,
                                       atoms=None,
                                       atomtypes=None)
     self.assertEqual(self.Crystal.cell, self.cell)