def test_selectors(self):

        # Multiple tests for various methods
        a = Atoms('HCHC',
                  positions=[[i] * 3 for i in range(4)],
                  cell=[4] * 3,
                  pbc=[True] * 3)

        # Element test
        s1 = AtomSelection.from_element(a, 'C')

        self.assertTrue(set(s1.indices) == set([1, 3]))

        # Box test
        s1 = AtomSelection.from_box(a, [1.5] * 3, [4.5] * 3, periodic=True)
        s2 = AtomSelection.from_box(a, [1.5] * 3, [4.5] * 3, periodic=False)
        s3 = AtomSelection.from_box(a, [0.375] * 3, [1.125] * 3,
                                    periodic=True,
                                    scaled=True)

        self.assertTrue(set(s1.indices) == set([0, 2, 3]))
        self.assertTrue(set(s2.indices) == set([2, 3]))
        self.assertTrue(set(s3.indices) == set([0, 2, 3]))

        # Sphere test

        s1 = AtomSelection.from_sphere(a, [0.5] * 3, 3, periodic=True)
        s2 = AtomSelection.from_sphere(a, [0.5] * 3, 3, periodic=False)

        self.assertTrue(set(s1.indices) == set([0, 1, 2, 3]))
        self.assertTrue(set(s2.indices) == set([0, 1, 2]))
Exemple #2
0
# in fractional coordinates (scaled=True).

# NOTE: the plane is defined by the plane equation cohefficients.
# So for ax+by+cz+d = 0 we have [a,b,c,d]

nh3r = mirr(nh3l)

print "---- Coordinates of Hydrogen atoms in left and right versions of the molecule ----\n"
print "nh3l:\n", nh3Hsel.subset(nh3l).get_positions(), "\n"
print "nh3r:\n", nh3Hsel.subset(nh3r).get_positions(), "\n"
"""
3 - SELECTION VALIDATION

As a safety against mistakes, by default, any AtomSelection has its "validate" property initialised to True.
This means that whenever the selection is used to create a subset or make a transform a check is performed to verify
that the chemical symbols of the Atoms object it is operating on is the same as the one on which it was originally
created. In other words, selections shouldn't be able to operate on structures they don't refer to.
"""

# Create two structures
a1 = Atoms('HCO')
a2 = Atoms('FeAgAu')

# Create a selection
sel1 = AtomSelection.from_sphere(a1, [0, 0, 0], 0.1)

# Try using it on the wrong structure
try:
    a0 = sel1.subset(a2)
except ValueError as e:
    print "An error has verified: \n>\t", e