def test_applyQuaternion04(self): """applyQuaternion04 -- random pts 360 about random-axis""" state = StateToCoords(self.random_points, tolist=1) q = RandomArray.uniform(self.min, self.max, (4, )) q[3] = 360.0 result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result)
def test_applyQuaternion05(self): """applyQuaternion05 -- random pts 3*120 about x-axis""" state = StateToCoords(self.random_points, tolist=1) q = (0.0, 0.0, 1.0, 120.0) for n in range(3): result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result, 0)
def test_applyTranslation03(self): """applyTranslation03 -- random pts x (random there and back)""" state = StateToCoords(self.random_points, tolist=1) trn = RandomArray.uniform(self.min, self.max, (3,)) state.applyTranslation(trn) trn = -1*trn self.assertArrayEqual(self.random_points, state.applyTranslation(trn))
def test_applyTranslation03(self): """applyTranslation03 -- random pts x (random there and back)""" state = StateToCoords(self.random_points, tolist=1) trn = RandomArray.uniform(self.min, self.max, (3, )) state.applyTranslation(trn) trn = -1 * trn self.assertArrayEqual(self.random_points, state.applyTranslation(trn))
def test_applyQuaternion05(self): """applyQuaternion05 -- random pts 3*120 about x-axis""" state = StateToCoords(self.random_points, tolist=1) q = (0.0, 0.0, 1.0, 120.0) for n in xrange(3): result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result,0)
def test_applyQuaternion04(self): """applyQuaternion04 -- random pts 360 about random-axis""" state = StateToCoords(self.random_points, tolist=1) q = RandomArray.uniform(self.min, self.max, (4,)) q[3] = 360.0 result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result)
def test_applyQuaternion03(self): """applyQuaternion02 -- known pts 90 about z-axis""" state = StateToCoords(self.known_points, tolist=1) result = state.applyQuaternion((0.0, 0.0, 1.0, 90.0)) expected = [[0., 1., 2.], [0., 1., 1.], [-1., 1., 1.], [0., 0., 1.], [0., 0., 0.], [-1., 0., 0.], [-1., 0., -1.], [-1., 1., -1.], [-2., 1., -1.], [-1., 1., -2.]] self.assertArrayEqual(expected, result)
def test_applyQuaternion06(self): """applyQuaternion06 -- random pts 2*180 about random-axis""" state = StateToCoords(self.random_points, tolist=1) q = RandomArray.uniform(self.min, self.max, (4, )) q[3] = 180.0 for n in range(2): result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result)
def test_applyQuaternion06(self): """applyQuaternion06 -- random pts 2*180 about random-axis""" state = StateToCoords(self.random_points, tolist=1) q = RandomArray.uniform(self.min, self.max, (4,)) q[3] = 180.0 for n in xrange(2): result = state.applyQuaternion(q) self.assertArrayEqual(self.random_points, result)
def test_applyQuaternion021(self): """applyQuaternion021 -- known pts 90 about x-axis; origin(1., 0., 1.)""" state = StateToCoords(self.known_points, tolist=1) result = state.applyQuaternion((1.0, 0.0, 0.0, 90.0), (1., 0., 1.)) expected = [[1., -1., 1.], [1., 0., 1.], [1., 0., 2.], [0., 0., 1.], [0., 1., 1.], [0., 1., 2.], [0., 2., 2.], [1., 2., 2.], [1., 2., 3.], [1., 3., 2.]] self.assertArrayEqual(expected, result)
def test_applyOrientation01(self): """applyOrientation01 -- Q, T, O combined""" state = StateToCoords(self.known_points, tolist=1) result = state.applyOrientation(quat=(1.0, 0.0, 0.0, 90.0), trans=(10., 10., 10.), origin=(1., 0., 1.)) expected = [[11., 9., 11.], [11., 10., 11.], [11., 10., 12.], [10., 10., 11.], [10., 11., 11.], [10., 11., 12.], [10., 12., 12.], [11., 12., 12.], [11., 12., 13.], [11., 13., 12.]] self.assertArrayEqual(expected, result)
def test_applyState(self): """applyState -- computed values untested""" value = TestState(q=(1.0, 0.0, 0.0, 90.0), t=(10., 10., 10.), o=(1., 0., 1.), tList=[0., 0., 270.]) state = StateToCoords(self.known_points, self.torTree, tolist=1) result = state.applyState(value) expected = [[11., 9., 11.], [11., 10., 11.], [11., 10., 12.], [10., 10., 11.], [10., 11., 11.], [10., 11., 12.], [10., 12., 12.], [11., 12., 12.], [11., 13., 12.], [11., 12., 11.]] self.assertArrayEqual(expected, result)
def test_applyQuaternion03(self): """applyQuaternion02 -- known pts 90 about z-axis""" state = StateToCoords(self.known_points, tolist=1) result = state.applyQuaternion((0.0, 0.0, 1.0, 90.0)) expected = [[ 0., 1., 2.], [ 0., 1., 1.], [-1., 1., 1.], [ 0., 0., 1.], [ 0., 0., 0.], [-1., 0., 0.], [-1., 0., -1.], [-1., 1., -1.], [-2., 1., -1.], [-1., 1., -2.]] self.assertArrayEqual(expected, result)
def test_applyOrientation01(self): """applyOrientation01 -- Q, T, O combined""" state = StateToCoords(self.known_points, tolist=1) result = state.applyOrientation( quat=(1.0, 0.0, 0.0, 90.0), trans= (10., 10., 10.), origin=(1., 0., 1.)) expected = [[11., 9., 11.], [11., 10., 11.], [11., 10., 12.], [10., 10., 11.], [10., 11., 11.], [10., 11., 12.], [10., 12., 12.], [11., 12., 12.], [11., 12., 13.], [11., 13., 12.]] self.assertArrayEqual(expected, result)
def __init__(self, mol, origin): """ """ self.mol = mol self.origin = origin self.conformations = [] #conformations are 1-based to fit with autodock 1-based rank self.current_conf = None mol.allAtoms.addConformation(mol.allAtoms.coords) self.confIndex = len(mol.allAtoms[0]._coords) - 1 if hasattr(mol, 'torTree'): mol.stoc = self.stoc = StateToCoords(mol, origin, self.confIndex)
def test_applyQuaternion01(self): """applyQuaternion01 -- known pts 360 about x-axis""" state = StateToCoords(self.known_points, tolist=1) result = state.applyQuaternion((1.0, 0.0, 0.0, 360.0)) self.assertArrayEqual(self.known_points, result)
def test_applyOrientation00(self): """applyOrientation00 -- random pts with defaults""" state = StateToCoords(self.random_points, tolist=1) self.assertEqual(self.random_points, state.applyOrientation())
def test_applyTranslation00(self): """applyTranslation00 -- random pts x (0., 0., 0.)""" state = StateToCoords(self.random_points, tolist=1) zzz = Numeric.zeros((3,), 'f') self.assertEqual(self.random_points, state.applyTranslation(zzz))
def test_applyTranslation02(self): """applyTranslation02 -- known pts x (1., 1., 1.)""" state = StateToCoords(self.known_points, tolist=1) ones = numpy.ones((3, ), 'f') expected = (numpy.array(self.known_points) + ones).tolist() self.assertEqual(expected, state.applyTranslation(ones))
def test_applyTranslation01(self): """applyTranslation01 -- random pts x (random translation)""" state = StateToCoords(self.random_points, tolist=0) trn = RandomArray.uniform(self.min, self.max, (3, )) expected = (numpy.array(self.random_points) + trn) self.assertArrayEqual(expected, state.applyTranslation(trn))
def test_applyTranslation00(self): """applyTranslation00 -- random pts x (0., 0., 0.)""" state = StateToCoords(self.random_points, tolist=1) zzz = numpy.zeros((3, ), 'f') self.assertEqual(self.random_points, state.applyTranslation(zzz))
def test_applyTranslation01(self): """applyTranslation01 -- random pts x (random translation)""" state = StateToCoords(self.random_points, tolist=0) trn = RandomArray.uniform(self.min, self.max, (3,)) expected = (Numeric.array(self.random_points) + trn) self.assertArrayEqual(expected, state.applyTranslation(trn))
def test_applyTranslation02(self): """applyTranslation02 -- known pts x (1., 1., 1.)""" state = StateToCoords(self.known_points, tolist=1) ones = Numeric.ones((3,), 'f') expected = (Numeric.array(self.known_points) + ones).tolist() self.assertEqual(expected, state.applyTranslation(ones))
sys.exit() m = Read(filename)[0] if verbose: print('read ', filename) #validate specified ligand file assert hasattr(m, 'torTree'), "specified ligand does not have a torsion tree" ndihe = m.parser.keys.count('BRANCH') if verbose: print(m.name, ' has ', ndihe, ' torsions') #1. prepare molecule m.buildBondsByDistance() orig_coords = m.allAtoms.coords[:] m.allAtoms.addConformation(m.allAtoms.coords) coord_index = 1 origin = m.getCenter() m.stoc = StateToCoords(m, origin, 1) #build reference dictionary of original bonds orig = len(m.allAtoms.bonds[0]) orig_d = {} for a in m.allAtoms: orig_d[a]=set(a.bonds.getAtoms()) #try a new random state up to ntries times # convert trans to space centered on m for new_try in range(ntries): #reset coords in working slot to original coords for new try m.allAtoms.updateCoords(orig_coords, ind=coord_index) TRANS = [] for ind in range(3): #do not subtract origin here, i don't understand why not #TRANS.append((random.uniform(-1,1)*tscale)-origin[i]) TRANS.append(random.uniform(-1,1)*tscale)
lig.buildBondsByDistance() # add extra slot to ._coords for changing coordinates lig.allAtoms.addConformation(lig.allAtoms.coords) #?is this necessary lig.allAtoms.setConformation(1) ntors = lig.ndihe length_of_state = 7 + lig.ndihe # @@ handle to the input ligLines ligLines = lig.parser.allLines #setup StateToCoords object origin = lig.getCenter() if use_zero_origin or interim_state: origin = [0., 0., 0.] #note: index of _coords to use is always 1 lig.stoc = StateToCoords(lig, origin, 1) outptr = sys.stdout if outputfile: outptr = open(outputfile, 'w') #if SINGLESTATE: # eg: #"State: 29.303 14.415 23.603 0.5609 0.4518 0.2662 -0.6406 -20.89 -0.65 81.86 -17.36 28.83 -10.80 -23.98 114.21" #states = state.split() #['State:', '29.303', '14.415', '23.603', '0.5609', '0.4518', '0.2662', '-0.6406', '-20.89', '-0.65', '81.86', '-17.36', '28.83', '-10.80', '-23.98', '114.21'] if statefile: sptr = open(statefile) states = sptr.readlines() sptr.close() if not len(states):