def test_inv_rotation(self): """rotate two water molecules by random angles, translate them in random space, one by oxygen other by center of mass rotate them to standard orientation and center by mass""" w1 = Water.get_standard() w2 = Water.get_standard() t1, t2, t3 = np.random.uniform( -np.pi, np.pi, [3] ) d1, d2, d3 = np.random.uniform( -np.pi, np.pi, [3] ) r1, r2 = np.random.uniform( -100, 100, [2,3] ) w1.translate_o( r1 ) w2.translate( r1 ) w1.rotate( t1, t2, t3 ) w2.rotate( d1, d2, d3 ) w1.inv_rotate( t3, t2, t1 ) w2.inv_rotate( d3, d2, d1 ) w1.center() w2.center() self.eq ( w1.com, w2.com )
def test_three_waters(self): s = System() ch1, ch2 = Chain(), Chain() ch1.chain_id = 'A' ch2.chain_id = 'B' w1, w2 = Water.get_standard( AA = True ), Water.get_standard( AA = True ) ch1.add( w1 ) ch2.add( w2 ) #After rotating and translating both waters oxygen is 2 AA apart w1.rotate( 0, np.pi/2, 0 ) w2.rotate( 0, -np.pi/2, 0 ) w1.t( -1, 0, 0 ) w2.t( 1, 0, 0 ) s.add( ch1 ) s.add( ch2 ) assert len( s.min_dist_atoms_separate_res_chain( 2.1 ) ) == 2 ch2.chain_id = 'A' assert len( s.min_dist_atoms_separate_res_chain( 2.1 ) ) == 0
def test_additive_pdlist(self): """Should give only props from oxygen to h2 since there is no bond from h1 to oxygen to oxygen""" w1 = Water.get_standard() w2 = Water.get_standard().t( 0, 0, 5 ) w3 = Water.get_standard() w4 = Water.get_standard().t( 0, 0, 5 ) w1.props_from_targz( WATER_FILE_TARGZ, bonds = 0, maxl = 1) w2.props_from_targz( WATER_FILE_TARGZ, bonds = 0, maxl = 1) w3.props_from_targz( WATER_FILE_TARGZ, bonds = 1, maxl = 1) w4.props_from_targz( WATER_FILE_TARGZ, bonds = 1, maxl = 1) b1 = Cluster( w1, w2 ).get_pdlist( model = 'add', bonds = 0 ).beta( cython =1 ) b2 = Cluster( w3, w4 ).get_pdlist( model = 'add', bonds = 1 ).beta( cython =1 ) np.testing.assert_allclose( b1, b2 )
def setUp(self): self.ut_alpha = np.random.random( (6, ) ) self.ut_beat = np.random.random( (10, ) ) self.g = Generator() self.w = Water.get_standard() self.w.translate_by_r( np.random.uniform( -10, 10, [3] ) ) self.t1 = np.random.uniform( 0, np.pi/2 ) self.t2 = np.random.uniform( 0, np.pi ) self.t3 = np.random.uniform( 0, np.pi/2 )
def test_moved_get_euler(self): w = Water.get_standard() w.translate([5,5,5]) t1, t2 ,t3 = w.get_euler( lambda x: (x.o.r, (x.h1.r-x.h2.r)/2.0 + x.h2.r, x.h1.r )) w.center() self.eq( [t1, t2, t3] , np.zeros(3) ) t1, t2 ,t3 = w.get_euler(lambda x: (x.o.r, (x.h1.r-x.h2.r)/2.0 + x.h2.r, x.h1.r )) w.center() self.eq( [t1, t2, t3] , np.zeros(3) )
def test_centered_simple(self): w = Water.get_standard() w.attach_properties( loprop = 0 ) w.rotate( *np.random.random( (3,) )) w.t( np.random.uniform( 0, 5, (3,) )) p_ref = w.p.copy() w.attach_properties( loprop = 0 ) np.testing.assert_allclose( w.p.d, p_ref['dipole'], atol = 1e-7 ) np.testing.assert_allclose( w.p.b, p_ref['beta'], atol = 1e-7 ) np.testing.assert_allclose( w.p.a, p_ref['alpha'], atol = 1e-7 )
def test_attach_properties(self): w = Water.get_standard() t, r1, r2, r3 = utilz.center_and_xz( w.o.r, (w.h1.r - w.h2.r)/2.0 + w.h2.r, w.h1.r ) w.o.pdb_name = 'OW' w.h1.pdb_name = 'HW1' w.h2.pdb_name = 'HW2' w.attach_properties( model = 'TIP3P_PDB', method = 'B3LYP', basis ='ANO631', template_key = lambda x: x.pdb_name, force_template = True ) np.testing.assert_allclose( w.p.q , 0.0, atol = 1e-4 )
def test_reflection(self): """docstring for test_reflection""" w = Water.get_standard() w.attach_properties( force_template = True) w.rotate( 0, np.pi/3.0, 0 ) b_ref = w.p.b_proj.copy() d_ref = w.p.d.copy() w.reflect( plane = 'zy' ) np.testing.assert_allclose( w.p.q, 0.0, atol = 1e-7 ) np.testing.assert_allclose( w.p.b_proj, b_ref, atol = 1e-7 ) np.testing.assert_allclose( abs(w.p.d), abs( d_ref ), atol = 1e-5 )
def test_transfer_props(self): w = Water.get_standard() w.populate_bonds() w.props_from_targz( WATER_FILE_TARGZ, bonds = 1, maxl = 1, pol = 22, hyp = 1 ) q_ref = w.p.q a_ref = w.p.a.copy() w.o.transfer_props( 2 ) np.testing.assert_allclose( w.h1.q, 0.0, atol = 1e-7 ) np.testing.assert_allclose( w.h2.q, 0.0, atol = 1e-7 ) np.testing.assert_allclose( w.p.q, q_ref, atol = 1e-7 ) np.testing.assert_allclose( w.p.a, a_ref, atol = 1e-7 )
def test_reflection2(self): w = Water.get_standard() w.attach_properties( force_template = True ) q = w.p.q d = w.p.d.copy() Q = w.p.Q.copy() a = w.p.a.copy() b = w.p.b.copy() w.rotate( 0, np.pi/2, 0, ) w.reflect( 'zy' ) w.rotate( 0, np.pi/2, 0, ) np.testing.assert_allclose( q, w.p.q, atol = 1e-7 ) np.testing.assert_allclose( d, w.p.d, atol = 1e-7 ) np.testing.assert_allclose( Q, w.p.Q, atol = 1e-7 ) np.testing.assert_allclose( a, w.p.a, atol = 1e-7 ) np.testing.assert_allclose( b, w.p.b, atol = 1e-7 )
def test_transfer_props_asymm(self): """Should give only props from oxygen to h2 since there is no bond from h1 to oxygen to oxygen""" w = Water.get_standard() w.populate_bonds() w.props_from_targz( WATER_FILE_TARGZ, bonds = 1, maxl = 1, pol = 22, hyp = 1 ) w.h1._res_id = 2 q_ref = w.p.q q_h2_ref = w.o.p.q q_o_ref = w.h2.p.q a_ref = w.p.a.copy() w.o.transfer_props( 2 ) np.testing.assert_allclose( w.h2.q, q_h2_ref + q_o_ref , atol = 1e-7 ) np.testing.assert_allclose( w.p.q, q_ref, atol = 1e-7 ) np.testing.assert_allclose( w.p.a, a_ref, atol = 1e-7 )
def test_center_get_euler(self): w = Water.get_standard() t1, t2, t3 = w.get_euler( lambda x: (x.o.r, (x.h1.r-x.h2.r)/2.0 + x.h2.r, x.h1.r )) self.eq( [t1, t2, t3] , np.zeros(3) )
def test_get_mol(self): w = Water.get_standard() self.assertIsInstance( w, Molecule )