Пример #1
0
    def test_atom_ordering(self):
        all_dists = bond_length_distribution.AllAtomPairLengthDistributions()
        all_dists.add(ATOM_N, ATOM_O, BOND_SINGLE,
                      bond_length_distribution.FixedWindow(1, 2, None))
        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_N, ATOM_O, BOND_SINGLE, 1.5),
            1)
        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_O, ATOM_N, BOND_SINGLE, 1.5),
            1)

        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_N, ATOM_O, BOND_SINGLE, 999),
            0)
        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_O, ATOM_N, BOND_SINGLE, 999),
            0)

        # Make sure subsequent additions work as well
        all_dists.add(ATOM_N, ATOM_O, BOND_DOUBLE,
                      bond_length_distribution.FixedWindow(2, 3, None))
        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_N, ATOM_O, BOND_DOUBLE, 2.5),
            1)
        self.assertEqual(
            all_dists.pdf_length_given_type(ATOM_O, ATOM_N, BOND_DOUBLE, 2.5),
            1)
Пример #2
0
 def setUp(self):
     super().setUp()
     self.dists = bond_length_distribution.AtomPairLengthDistributions()
     self.dists.add(BOND_SINGLE,
                    bond_length_distribution.FixedWindow(1.2, 1.8, None))
     self.dists.add(BOND_DOUBLE,
                    bond_length_distribution.FixedWindow(1.0, 1.4, None))
Пример #3
0
 def test_probability_bond_types(self):
     all_dists = bond_length_distribution.AllAtomPairLengthDistributions()
     all_dists.add(ATOM_N, ATOM_O, BOND_SINGLE,
                   bond_length_distribution.FixedWindow(1, 4, None))
     all_dists.add(ATOM_N, ATOM_O, BOND_DOUBLE,
                   bond_length_distribution.FixedWindow(1, 2, None))
     got = all_dists.probability_of_bond_types(ATOM_N, ATOM_O, 1.5)
     self.assertLen(got, 2)
     self.assertAlmostEqual(got[BOND_SINGLE], 0.25)
     self.assertAlmostEqual(got[BOND_DOUBLE], 0.75)
Пример #4
0
    def test_simple(self):
        dist = bond_length_distribution.Mixture()
        dist.add(bond_length_distribution.FixedWindow(0.5, 1.5, None), 75)
        dist.add(bond_length_distribution.FixedWindow(1, 2, None), 25)
        self.assertAlmostEqual(dist.pdf(0.25), 0)
        self.assertAlmostEqual(dist.pdf(0.75), .75)
        self.assertAlmostEqual(dist.pdf(1.25), 1)
        self.assertAlmostEqual(dist.pdf(1.75), .25)
        self.assertAlmostEqual(dist.pdf(2.25), 0)

        self.assertEqual(dist.min(), 0.5)
        self.assertEqual(dist.max(), 2)
Пример #5
0
 def test_simple(self):
     dist = bond_length_distribution.FixedWindow(3, 5, None)
     self.assertAlmostEqual(dist.pdf(2.9), 0.0)
     self.assertAlmostEqual(dist.pdf(5.1), 0.0)
     self.assertAlmostEqual(dist.pdf(3.456), 0.5)
     self.assertEqual(dist.min(), 3)
     self.assertEqual(dist.max(), 5)
Пример #6
0
 def get_smu_dists(self):
   bld = bond_length_distribution.AllAtomPairLengthDistributions()
   # This is set up to make the O=C length of 1.25 a much better fit than
   # the [O-]-C bond
   bld.add(dataset_pb2.BondTopology.ATOM_O, dataset_pb2.BondTopology.ATOM_C,
           dataset_pb2.BondTopology.BondType.BOND_SINGLE,
           triangular_distribution(1.2, 1.6, 1.8))
   bld.add(dataset_pb2.BondTopology.ATOM_O, dataset_pb2.BondTopology.ATOM_C,
           dataset_pb2.BondTopology.BondType.BOND_DOUBLE,
           triangular_distribution(1.2, 1.25, 1.3))
   bld.add(dataset_pb2.BondTopology.ATOM_C, dataset_pb2.BondTopology.ATOM_N,
           dataset_pb2.BondTopology.BondType.BOND_DOUBLE,
           bond_length_distribution.FixedWindow(1.1, 1.3, None))
   bld.add(dataset_pb2.BondTopology.ATOM_C, dataset_pb2.BondTopology.ATOM_N,
           dataset_pb2.BondTopology.BondType.BOND_TRIPLE,
           bond_length_distribution.FixedWindow(1.2, 1.4, None))
   return bld
Пример #7
0
    def test_missing_types(self):
        all_dists = bond_length_distribution.AllAtomPairLengthDistributions()
        all_dists.add(ATOM_N, ATOM_O, BOND_SINGLE,
                      bond_length_distribution.FixedWindow(1, 2, None))

        with self.assertRaises(KeyError):
            all_dists.probability_of_bond_types(ATOM_C, ATOM_C, 1.0)

        with self.assertRaises(KeyError):
            all_dists.pdf_length_given_type(ATOM_C, ATOM_C, BOND_SINGLE, 1.0)
Пример #8
0
 def test_right_tail(self):
     dist = bond_length_distribution.FixedWindow(3, 5, right_tail_mass=0.8)
     # 0.2 of the mass is in the window, divded by 2 (size of the window)
     self.assertAlmostEqual(dist.pdf(3.456), 0.1)
     self.assertAlmostEqual(dist.pdf(5), 0.1)
     # Test slightly above the maximum to make sure we got the left side of the
     # right tail correct.
     self.assertAlmostEqual(dist.pdf(5.00000001), 0.1)
     self.assertAlmostEqual(dist.pdf(6), 0.08824969)
     self.assertEqual(dist.min(), 3)
     self.assertEqual(dist.max(), np.inf)
Пример #9
0
 def test_bad_values(self):
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(-1, 1, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(-2, -1, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(10, 8, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(np.inf, 1, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(np.nan, 1, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(1, np.inf, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(1, np.nan, None)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(1, 2, -1.0)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(1, 2, 2)
     with self.assertRaises(ValueError):
         bond_length_distribution.FixedWindow(1, 2, np.inf)
Пример #10
0
 def test_bad_weight(self):
     dist = bond_length_distribution.Mixture()
     with self.assertRaises(ValueError):
         dist.add(bond_length_distribution.FixedWindow(1, 2, None), 0)
     with self.assertRaises(ValueError):
         dist.add(bond_length_distribution.FixedWindow(1, 2, None), 0)