Exemple #1
0
    def test_Crystal(self):
        ''' Make a Crystal and check some stuff '''
        from analyseClusters import getSpeciesListCIF, Crystal, splitASEAtomsToMols
        structures = list(getSpeciesListCIF('CSPPCM_example.cif'))

        #take the z'=2 one
        myCrystal = Crystal(splitASEAtomsToMols(structures[-2]))

        self.assertEqual(len(myCrystal.asymmetricMolecules), 2)
        self.assertEqual(len(myCrystal.asymmetricMolecules[-1].aseAtoms), 33)

        myCrystal.generateNeighbouringAtoms(nMolecules=16)
        self.assertEqual(len(myCrystal.asymmetricMolecules[0].listNeighbours),
                         16)
        self.assertEqual(len(myCrystal.asymmetricMolecules[1].listNeighbours),
                         16)

        myCrystal.calculateClusterInformation([1, 0, 2], [6, 15, 7, 8],
                                              groupLabels=groupLabels['MFA'])
        self.assertEqual(
            myCrystal.asymmetricMolecules[1].environment['v(com)'].shape,
            (16, 3))
        self.assertEqual(
            myCrystal.asymmetricMolecules[0].environment['r(com)'].shape,
            (16, ))
Exemple #2
0
    def test_readCIFAndManipulate(self):
        #check can split up a 'molecule' into molecules
        from analyseClusters import getSpeciesListCIF

        #        structs = ASERead('CSPPCM_example.cif', index=':') #old way - dont do this
        structures = list(getSpeciesListCIF('CSPPCM_example.cif'))

        self.assertEqual(len(structures), 7)
        from analyseClusters import splitASEAtomsToMols
        self.assertEqual(len(structures[-2]), 66)
        self.assertEqual([len(x) for x in splitASEAtomsToMols(structures[-2])],
                         [33, 33])

        #demonstrate that positions can be retrieved to full accuracy
        splitStructure = splitASEAtomsToMols(structures[-2],
                                             useOriginalPositions=False)
        np.testing.assert_array_almost_equal(
            np.array([x.position for x in structures[-2]]),
            np.array(np.vstack([x.get_positions() for x in splitStructure])),
            decimal=2)
        splitStructure = splitASEAtomsToMols(structures[-2])
        np.testing.assert_array_almost_equal(
            np.array([x.position for x in structures[-2]]),
            np.array(np.vstack([x.get_positions() for x in splitStructure])))
 def test_printStuff(self):
     from analyseClusters import getSpeciesListCIF, Surface, splitASEAtomsToMols
     return
     #        mySurface = Surface(splitASEAtomsToMols(structures[-2]), millerIndex = np.array([1,1,1]))
     structures = list(getSpeciesListCIF('CSPPCM_example.cif'))
     #take the z'=2 one - but hack it to make one atom per mol
     hackMols = splitASEAtomsToMols(structures[-2])
     from ase import Atoms
     #draw the cell (for some reason, it may help to see it)
     mySurface.asymmetricMolecules = mySurface.filledUnitCellMolecules()
     mySurface.writeASEAtoms('originalSetting.cif')
     _cifName = 'exampleSurface.cif'
     if os.path.isfile(_cifName):
         os.remove(_cifName)
     mySurface.writeASEAtoms(_cifName, pbc=False)
     self.assertTrue(os.path.isfile(_cifName))
    def test_makeSurface(self):
        from analyseClusters import getSpeciesListCIF, Surface, splitASEAtomsToMols

        structures = list(getSpeciesListCIF('CSPPCM_example.cif'))
        #take the z'=2 one - but hack it to make one atom per mol
        hackMols = splitASEAtomsToMols(structures[-2])
        from ase import Atoms

        mySurface = Surface(hackMols)

        #try simple cells and cell returning sensible cells
        _oldCell = mySurface.aseCell
        mySurface = Surface(hackMols, millerIndex=np.array([0, 1, 0]))
        np.testing.assert_array_almost_equal(
            np.dot(np.array([[0., 0., 1.], [1., 0., 0.], [0., 1., 0.]]),
                   _oldCell), mySurface.aseCell)
        mySurface = Surface(hackMols, millerIndex=np.array([1, 0, 0]))
        np.testing.assert_array_almost_equal(
            np.dot(
                np.array([[0., 0., 1.], [1., 0., 0.], [0., 1., 0.]]).T,
                _oldCell), mySurface.aseCell)
        #this needs a cubic cell otherwise becomes big
        hackMols = [
            Atoms(symbols=['C'],
                  positions=[hackMols[0].get_center_of_mass()],
                  cell=hackMols[0].cell,
                  info=hackMols[0].info),
            Atoms(symbols=['Xe'],
                  positions=[hackMols[1].get_center_of_mass()],
                  cell=hackMols[1].cell,
                  info=hackMols[1].info)
        ]
        hackMols = [
            Atoms(symbols=['Xe', 'C'],
                  positions=[[0.25, 0.5, 0.75], [0.75, 1., 1.]],
                  cell=[[1., 0., 0.], [0., 2., 0.], [0., 0., 3]],
                  info=hackMols[0].info)
        ]
        mySurface = Surface(hackMols, millerIndex=np.array([0, 0, 1]))
        np.testing.assert_array_almost_equal(np.diag([1., 2., 3.]),
                                             mySurface.aseCell)

        #try other cuts
        mySurface.writeASEAtoms('hack001.cif')
        mySurface = Surface(hackMols, millerIndex=np.array([0, 1, 1]))
        mySurface.writeASEAtoms('hack011.cif')
    def test_CrystalSubroutines(self):
        from analyseClusters import getSpeciesListCIF, Crystal, splitASEAtomsToMols

        structures = list(getSpeciesListCIF('CSPPCM_example.cif'))
        #take the z'=2 one
        myCrystal = Crystal(splitASEAtomsToMols(structures[-2]))
        #spacegroup 7, z'2 = 4
        self.assertTrue(len(myCrystal.filledUnitCellMolecules()), 4)

        #check that in ase the convention is cartVec = fracVec.Cell
        np.testing.assert_array_almost_equal(
            myCrystal.asymmetricMolecules[0].aseAtoms.get_center_of_mass(),
            np.dot(
                myCrystal.asymmetricMolecules[0].aseAtoms.get_center_of_mass(
                    scaled=True), myCrystal.aseCell))

        #check that in ase the convention is fracVec = cartVec.(Cell^-1)
        np.testing.assert_array_almost_equal(
            myCrystal.asymmetricMolecules[0].aseAtoms.get_center_of_mass(
                scaled=True),
            np.dot(
                myCrystal.asymmetricMolecules[0].aseAtoms.get_center_of_mass(),
                np.linalg.inv(myCrystal.aseCell)))