def parsegene_hbonds_site_reference(c, ref=None): if ref is None: ref = c.structures[0] # First, calculate molecules, molecule sites and hydrogen bonds MoleculeSites.get(ref) HydrogenBonds.get(ref) MoleculeSites.get(c) HydrogenBonds.get(c) # Now for the actual comparison we need to compile a list of Hbonds # for each structure, expressed in terms of molecular sites reflabels = HydrogenBondTypes.get(ref) hblabels = HydrogenBondTypes.get(c) # And now to actually create a comparison distL = [] for hb_lab in hblabels: distL.append(list_distance(hb_lab, reflabels)) return np.array(distL)
def extract(s, force_recalc, save_info): # First, we need the molecules if Molecules.default_name not in s.info or force_recalc: Molecules.get(s) # Then the hydrogen bonds if HydrogenBonds.default_name not in s.info or force_recalc: HydrogenBonds.get(s) # Finally the sites if MoleculeSites.default_name not in s.info or force_recalc: MoleculeSites.get(s) mols = s.info[Molecules.default_name] hbonds = s.info[HydrogenBonds.default_name] all_sites = s.info[MoleculeSites.default_name] hblabels = [] for hbtype in hbonds: for hb in hbonds[hbtype]: A_i = hb['A'][0] H_i = hb['H'] B_i = hb['B'][0] # Check in which molecule they are AH_sites = None B_sites = None for m_i, m in enumerate(mols): if A_i in m: AH_sites = all_sites[m_i] if B_i in m: B_sites = all_sites[m_i] if AH_sites is None or B_sites is None: raise RuntimeError('Invalid hydrogen bond detected') # Now build the proper definition hblabel = ('{0}<{1},{2}>' '..{3}<{4}>').format(AH_sites['name'], AH_sites['sites'][A_i], AH_sites['sites'][H_i], B_sites['name'], B_sites['sites'][B_i]) hblabels.append(hblabel) return sorted(hblabels)
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)
def parsegene_hbonds_site_compare(c): # First, calculate molecules, molecule sites and hydrogen bonds MoleculeSites.get(c) HydrogenBonds.get(c) # Now for the actual comparison we need to compile a list of Hbonds # for each structure, expressed in terms of molecular sites hblabels = HydrogenBondTypes.get(c) # And now to actually create a comparison distM = np.zeros((c.length, c.length)) for hb_i1, hb_lab1 in enumerate(hblabels): for hb_i2, hb_lab2 in enumerate(hblabels[hb_i1 + 1:]): d = list_distance(hb_lab1, hb_lab2) d /= (len(hb_lab1) + len(hb_lab2)) * 0.5 distM[hb_i1, hb_i1 + hb_i2 + 1] = d distM[hb_i1 + hb_i2 + 1, hb_i1] = d return distM
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)