def test_inf_2(self): a = numpy.array([util.INF, 3.0, 0.0], floattype) b = numpy.array([util.INF, 1.2, 2.3], floattype) c = numpy.array([0.3, util.INF, 29.02], floattype) d = numpy.array([2.1, 1.0, 29.02], floattype) result = sasmath.dihedral_angle(a, b, c, d) self.assertTrue(numpy.isnan(result) or numpy.isinf(result))
def test_nan(self): a = numpy.array([util.NAN, 3.0, 0.0], floattype) b = numpy.array([6.0, util.NAN, 2.0], floattype) c = numpy.array([util.NAN, 1.0, 0.0], floattype) d = numpy.array([2.1, 1.0, 29.02], floattype) result = sasmath.dihedral_angle(a, b, c, d) self.assertTrue(numpy.isnan(result))
def test_arb_1(self): a = numpy.array([23.0, 0.0, 0.0], floattype) b = numpy.array([0.0, 0.0, 0.0], floattype) c = numpy.array([0.0, 12.0, 0.0], floattype) d = numpy.array([0.0, 212.0, -20.0], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 90.0 self.assertAlmostEqual(result, expected)
def test_same_plane_1(self): a = numpy.array([1.0, 0.0, 0.0], floattype) b = numpy.array([0.0, 0.0, 0.0], floattype) c = numpy.array([0.0, 1.0, 0.0], floattype) d = numpy.array([1.0, 1.0, 0.0], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 0.0 self.assertAlmostEqual(result, expected)
def test_all_zero_arrays(self): a = numpy.array([0.0, 0.0, 0.0], floattype) b = numpy.array([0.0, 0.0, 0.0], floattype) c = numpy.array([0.0, 0.0, 0.0], floattype) d = numpy.array([0.0, 0.0, 0.0], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 180.0 self.assertAlmostEqual(result, expected)
def test_zero(self): a = numpy.array([util.ZERO, 3.0, 0.0], floattype) b = numpy.array([6.0, util.ZERO, 2.0], floattype) c = numpy.array([6.7, 1.0, util.ZERO], floattype) d = numpy.array([2.1, 1.0, 29.02], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 89.502 self.assertAlmostEqual(result, expected, 3)
def test_tiny(self): a = numpy.array([util.TINY, 3.0, 0.0], floattype) b = numpy.array([6.0, util.TINY, 2.0], floattype) c = numpy.array([2.0, 3.2, util.TINY], floattype) d = numpy.array([2.1, 1.0, 29.02], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 66.032 self.assertAlmostEqual(result, expected, 3)
def test_arb_2(self): a = numpy.array([1.0168308, -1.35572028, -1.35362422], floattype) b = numpy.array([-0.69958848, 1.66901076, 0.49978462], floattype) c = numpy.array([12.0168308, 12.35572028, 1.35362422], floattype) d = numpy.array([-20.69958848, 16.66901076, 20.49978462], floattype) c = numpy.array([0.3, 0.0, -1.2], floattype) result = sasmath.dihedral_angle(a, b, c, d) expected = 85.786 self.assertAlmostEqual(result, expected, 3)
def calculate_initial_torsion_variables(other_self, main_pivots_masks): mol = other_self.mol frame = 0 torsion_angles = [] for mask in main_pivots_masks: error, coor = mol.get_coor_using_mask(frame,mask) if len(error) > 0: log.error('ERROR: '+str(error)) else: c = coor[0] torsion_angles.append(sasmath.dihedral_angle(c[0],c[1],c[2],c[3])) #print torsion_angles[-1] return
def measure(other_self, group_molecule, group_number, pivot_number): mvars = other_self.mvars pvars = mvars.pvars log = other_self.log pgui = other_self.run_utils.print_gui main_pivots_mask = pvars.main_pivots_masks[group_number][pivot_number] coor = group_molecule.coor() log.debug('in measure') ##pgui('Indices of selected main_pivots_mask = '+str(numpy.nonzero(main_pivots_mask)[0])) ind=numpy.nonzero(main_pivots_mask*numpy.arange(1,len(main_pivots_mask)+1))[0] this_frame_coor = coor[0,:,:] lcoor=numpy.take(this_frame_coor[:,:],ind,0) angle=sasmath.dihedral_angle(lcoor[0,:],lcoor[1,:],lcoor[2,:],lcoor[3,:]) return angle
def measure(coor, indices, an, this_mask, q0, first_last_resid, molecule_type, drude=False): ind = numpy.nonzero(this_mask * numpy.arange(1, len(this_mask) + 1))[0] this_frame_coor = coor[0, :, :] lcoor = numpy.take(this_frame_coor[:, :], ind, 0) error = [] if(molecule_type == 'protein'): if(an == 'phi'): angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :]) elif(an == 'psi'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :]) else: angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :]) else: angle = 0.0 message = 'error (in rotate.measure): %s angle not in phi/psi' % an error.append(message) assert not error, error elif(molecule_type == 'rna'): if(an == 'alpha'): angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :]) elif(an == 'beta'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :]) else: angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :]) elif(an == 'gamma'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :]) else: angle = sasmath.dihedral_angle(lcoor[2, :], lcoor[3, :], lcoor[4, :], lcoor[5, :]) elif(an == 'delta'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[2, :], lcoor[3, :], lcoor[4, :], lcoor[5, :]) else: angle = sasmath.dihedral_angle(lcoor[3, :], lcoor[4, :], lcoor[5, :], lcoor[6, :]) elif(an == 'epsilon'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[3, :], lcoor[4, :], lcoor[5, :], lcoor[6, :]) else: angle = sasmath.dihedral_angle(lcoor[4, :], lcoor[5, :], lcoor[6, :], lcoor[7, :]) elif(an == 'eta'): if(q0 == first_last_resid[0]): angle = sasmath.dihedral_angle(lcoor[4, :], lcoor[5, :], lcoor[6, :], lcoor[7, :]) else: angle = sasmath.dihedral_angle(lcoor[5, :], lcoor[6, :], lcoor[7, :], lcoor[8, :]) else: angle = 0.0 message = ('error (in rotate.measure): %s angle not in ' 'alpha/beta/gamma/delta/epsilon/eta' % an) error.append(message) assert not error, error elif(molecule_type == 'dna'): if(first_last_resid[0] == first_last_resid[1]): print 'WARNING: only given one DNA base for calculating angles' print 'WARNING: change input or revise code' print 'WARNING: cowardly refusing to calculate angle, returni' return 0 # order of drude atoms differ from charmm27 (not sure about charmm36) if drude: i = {"O3'-1": 0, "P": 1, "O5'": 2, "C5'": 3, "chi3": 4, "chi4": 5,"C4'": 6, "O4'": 7, "C1'": 8, "C3'": 9, "O3'": 10, "P+1": 11, "O5'+1": 12} else: i = {"O3'-1": 0, "P": 1, "O5'": 2, "C5'": 3, "C4'": 4, "O4'": 5,"C1'": 6, "chi3": 7, "chi4": 8, "C3'": 9, "O3'": 10, "P+1": 11, "O5'+1": 12} if q0 == first_last_resid[0]: if len(lcoor) == 12: # missing the O3'-1 atom first_last_coor = numpy.zeros((13, 3)) first_last_coor[1:] = lcoor elif len(lcoor) == 11: # missing the O3'-1 and P atoms first_last_coor = numpy.zeros((13, 3)) first_last_coor[2:] = lcoor else: # not sure assert False, ('ERROR: cannot calculate dihedral angles from ' '%d atoms, not clear which atoms are which) \n' 'Please review atoms in PDB and input resids') if(an == 'alpha'): angle = numpy.nan return angle elif(an == 'beta' and len(lcoor) == 11): angle = numpy.nan return angle else: lcoor = numpy.copy(first_last_coor) if(an == 'alpha'): angle = sasmath.dihedral_angle( lcoor[i["O3'-1"], :], lcoor[i["P"], :], lcoor[i["O5'"], :], lcoor[i["C5'"], :]) elif(an == 'beta'): angle = sasmath.dihedral_angle( lcoor[i["P"], :], lcoor[i["O5'"], :], lcoor[i["C5'"], :], lcoor[i["C4'"], :]) elif(an == 'gamma'): angle = sasmath.dihedral_angle( lcoor[i["O5'"], :], lcoor[i["C5'"], :], lcoor[i["C4'"], :], lcoor[i["C3'"], :]) elif(an == 'delta'): angle = sasmath.dihedral_angle( lcoor[i["C5'"], :], lcoor[i["C4'"], :], lcoor[i["C3'"], :], lcoor[i["O3'"], :]) elif(an == 'epsilon'): if(q0 == first_last_resid[1]): assert len(lcoor) == 11, ('ERROR: expected 11 atoms for last ' 'resid but received %d' % len(lcoor)) angle = numpy.nan else: angle = sasmath.dihedral_angle( lcoor[i["C4'"], :], lcoor[i["C3'"], :], lcoor[i["O3'"], :], lcoor[i["P+1"], :]) elif(an == 'zeta'): if(q0 == first_last_resid[1]): assert len(lcoor) == 11, ('ERROR: expected 11 atoms for last ' 'resid but received %d' % len(lcoor)) angle = numpy.nan else: angle = sasmath.dihedral_angle( lcoor[i["C3'"], :], lcoor[i["O3'"], :], lcoor[i["P+1"], :], lcoor[i["O5'+1"], :]) elif(an == 'chi'): angle = sasmath.dihedral_angle( lcoor[i["O4'"], :], lcoor[i["C1'"], :], lcoor[i["chi3"], :], lcoor[i["chi4"], :]) else: angle = numpy.nan message = ('error (in rotate.measure): %s angle not in ' 'alpha/beta/gamma/delta/epsilon/zeta/chi' % an) error.append(message) assert not error, error return angle