def test_linkageprops(self):

        from soprano.properties.linkage import (LinkageList, Bonds,
                                                Molecules, MoleculeNumber,
                                                MoleculeMass,
                                                MoleculeCOMLinkage,
                                                MoleculeRelativeRotation,
                                                MoleculeSpectralSort,
                                                CoordinationHistogram,
                                                HydrogenBonds,
                                                HydrogenBondsNumber)

        from soprano.properties.transform import Rotate

        a = read(os.path.join(_TESTDATA_DIR, 'mol_crystal.cif'))

        # Test bonds
        testAtoms = Atoms(['C', 'C', 'C', 'C'],
                          cell=[5, 5, 5],
                          positions=np.array([[0, 0, 0],
                                              [4, 0, 0],
                                              [3, 3, 3],
                                              [3, 3.5, 3]]),
                          pbc=True)
        testBonds = Bonds.get(testAtoms)
        self.assertTrue(testBonds[0][:2] == (0, 1))
        self.assertTrue(testBonds[1][:2] == (2, 3))
        self.assertTrue(np.all(testBonds[0][2] == (-1, 0, 0)))
        self.assertAlmostEqual(testBonds[0][3], 2*testBonds[1][3])

        # Also test coordination histogram
        coord_hist = CoordinationHistogram.get(a)
        # Testing some qualities of the Alanine crystal...
        self.assertTrue(coord_hist['H']['C'][1], 16)    # 16 H bonded to a C
        self.assertTrue(coord_hist['H']['N'][1], 12)    # 12 H bonded to a N
        self.assertTrue(coord_hist['C']['H'][3], 4)     # 4 CH3 groups
        self.assertTrue(coord_hist['C']['O'][2], 4)     # 4 COO groups

        # Test molecules
        mols = Molecules.get(a)

        self.assertTrue(MoleculeNumber.get(a) == 4)
        self.assertTrue(np.isclose(MoleculeMass.get(a), 89.09408).all())
        self.assertTrue(len(MoleculeCOMLinkage.get(a)) == 6)

        # Spectral sorting
        elems = np.array(a.get_chemical_symbols())
        mol_specsort = MoleculeSpectralSort.get(a)
        for i in range(len(mols)-1):
            for j in range(i+1,len(mols)):
                self.assertTrue((elems[mol_specsort[i].indices] ==
                                 elems[mol_specsort[j].indices]).all())

        # Now testing hydrogen bonds
        hbs = HydrogenBonds.get(a)
        hbn = HydrogenBondsNumber.get(a)

        self.assertTrue(hbn['NH..O'] == 12)
        self.assertTrue(hbn['OH..O'] == 0)
Beispiel #2
0
def parsegene_hbonds_angle(c):
    hblist = HydrogenBonds.get(c)
    hbnlist = HydrogenBondsNumber.get(c)
    # Grab the maximum number for each of these
    hbnmax = np.amax(np.array(hbnlist), axis=0)

    # Now actually gather the lengths
    def cap_to(a, n):
        return a + [np.inf] * (n - len(a))

    hblens = []
    for hbn in hblist:
        # Extract lengths, order by key
        hblen = [
            sorted(cap_to([hb['angle'] for hb in hbn[hbs]], hbnmax[hbs]))
            for hbs in hbn
        ]
        hblen = list(itertools.chain(*hblen))
        hblens.append(hblen)

    return np.array(hblens)
Beispiel #3
0
def parsegene_hbonds_fprint(c):
    hblen = HydrogenBondsNumber.get(c)
    return np.array(
        [zip(*sorted(zip(ld.keys(), ld.values())))[1] for ld in hblen])
Beispiel #4
0
def parsegene_hbonds_totn(c):
    hblen = HydrogenBondsNumber.get(c)
    return np.array([sum(ld.values()) for ld in hblen])