def test_Nucleotide_across(): nucleotide = Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0]), ) # memory address of each object is stored # in the Nucleotide._across attribute new = nucleotide.make_across() assert id(new._across) == id(nucleotide) assert id(nucleotide._across) == id(new) # Should correctly raise some warnings and pass the # following assertions new_2 = nucleotide.make_across() assert id(new._across) != id(nucleotide) assert id(nucleotide._across) != id(new) assert id(new_2._across) == id(nucleotide) assert id(nucleotide._across) == id(new_2) # check the actual setting of indices works nucleotide.index = 0 new_2.index = 1 assert nucleotide.across == new_2.index assert new_2.across == nucleotide.index
def main(number: int = 10, double: bool = False): # Add Strand 1 - ssDNA n = number nucleotides = [] print("Creating a nucleotide:") nucleotides.append( Nucleotide(random.choice(['A', 'T', 'C', 'G']), np.array([0., -10., 0.]), a1=np.array([1., 0., 0.]), a3=np.array([0., 1., 0.]))) print(f"Nucleotide #0: {nucleotides[0]}") print("Creating more nucleotides...\n") for i in range(n): nucleotides.append( get_5p(nucleotides[-1], base=random.choice(['A', 'T', 'C', 'G']))) strand = Strand(nucleotides=nucleotides) print(f"Strand: {strand}") system = System(np.array([20., 20., 20.])) system.add_strand(strand) # Add Strand 2 - complementary ssDNA -> dsDNA if double: nucleotides = [] for nucleotide in strand.nucleotides[::-1]: nucleotides.append(get_across(nucleotide)) # for i in range(10): # nucleotides.append(get_5p(nucleotides[-1])) strand = Strand(nucleotides=nucleotides) print(f"Adding double: {strand}") system.add_strand(strand) system.write_oxDNA('local') return
def get_across(nuc: Nucleotide) -> Nucleotide: """ Returns Nucleotide o """ a1 = -nuc._a1 a3 = -nuc._a3 pos_com = nuc.pos_com - a1 * 2 * (POS_BASE + BASE_BASE) return Nucleotide(ACROSS[nuc._base], pos_com, a1, a3)
def test_nucleotide(): print( Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0]), ).lammps) return
def get_5p(nuc: Nucleotide, base: str = 'T') -> Nucleotide: # shift round in a1 direction angle = (np.pi / 180.0) * 35.9 rotation_matrix = get_rotation_matrix(nuc._a3, angle) a1 = np.dot( rotation_matrix, nuc._a1, ) # shift up in a3 direction new_base = nuc.pos_base + 0.39 * nuc._a3 new_pos = new_base - a1 * (POS_BASE) - 0.105 * np.cross(nuc._a3, a1) return Nucleotide(base, new_pos, a1, nuc._a3.copy())
def test_Nucleotide(): nucleotide = Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0]), ) assert len(nucleotide.series) == 10 assert (nucleotide.pos_back == [0.6, 0.0, 0.0]).all() assert (nucleotide.pos_back_rel == [-0.4, 0.0, 0.0]).all() assert (nucleotide.pos_base == [1.4, 0.0, 0.0]).all() assert (nucleotide.pos_stack == [1.34, 0.0, 0.0]).all() assert (nucleotide._a2 == [0.0, 1.0, 0.0]).all() print(nucleotide) print(nucleotide.series) nucleotide.make_5p('A') nucleotide.make_across() nucleotide.copy() return
def test_strand(): strand = Strand([ Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([2.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([3.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([4.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([5.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([6.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), ]) print(strand.lammps) return
def generate_helix( n: int = None, sequence: str = None, start_position: np.ndarray = np.array([0., 0., 0.]), direction: np.ndarray = np.array([0., 1., 0.]), a1: np.ndarray = np.array([1., 0., 0.]), initial_rotation: float = None, double: bool = False, enforce_180: bool = False, bp_per_turn: float = 10.45, ) -> List[Strand]: # handle sequence/n arguments if sequence and n: if len(sequence) != n: difference = len(sequence) - n # sequence longer than n if difference > 0: sequence = sequence[:n] # n longer than sequence else: sequence += ''.join([ random.choice(['A', 'T', 'C', 'G']) for i in range(-difference) ]) elif sequence: n = len(sequence) elif n: sequence = ''.join( [random.choice(['A', 'T', 'C', 'G']) for i in range(n)]) else: raise TypeError( 'Please provide either the number of base-pairs or a sequence') # handle a1/angle arguments if initial_rotation: a1 = get_rotation_matrix(direction, initial_rotation) if enforce_180: half_turns = round_to_multiple(n / bp_per_turn, 0.5, 1) angle = np.radians(360 * half_turns / (n - 1)) else: angle = 0.626 # initialise strand list strands = [] # create main strand strand = Strand() strand.add_nucleotide( Nucleotide(sequence[0], start_position, a1=a1, a3=direction)) for base in sequence[1:]: strand.add_nucleotide(strand.nucleotides[-1].make_5p(base, angle)) # add to strand list which will be returned strands.append(strand.copy()) # create across strand if double: strand = Strand() # iterate over nucleotides from original strand but in reverse for nucleotide in strands[0].nucleotides[::-1]: strand.add_nucleotide(nucleotide.make_across()) strands.append(strand.copy()) return strands
def test_System(): system = System(np.array([50.0, 50.0, 50.0])) strand_1 = Strand( [ Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([2.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([3.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([4.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([5.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "A", np.array([6.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), ] ) strand_2 = Strand( [ Nucleotide( "T", np.array([1.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "T", np.array([2.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "T", np.array([3.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "T", np.array([4.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "T", np.array([5.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), Nucleotide( "T", np.array([6.0, 2.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0, 0.0, 1.0]), ), ] ) system.add_strands([strand_1, strand_2]) assert isinstance(system, System) assert system.E_tot == 0.0 assert len(system.dataframe.count()) == 10 assert len(system.configuration.count()) == 5 assert len(system.topology.count()) == 4 assert len(system.strands) == 2 assert len(system.nucleotides) == 12 system.strands[0].sequence = "AGAGAG" system.add_strand(system.strands[0].copy()) system.strands[0].sequence = "TATATA" assert len(system.strands) == 3 assert len(system.nucleotides) == 18 assert system.strands[0].sequence == "TATATA" assert system.strands[2].sequence == "AGAGAG" strand_3 = system.strands[1].copy() strand_3.sequence = "CCCGGG" strand_4 = strand_3.copy() strand_4.sequence = "AAATTT" system.add_strands({ 0 : strand_3, 1 : strand_4 }) assert len(system.strands) == 5 assert len(system.nucleotides) == 30 print(system.strands) assert system.strands[0].sequence == "CCCGGG" assert system.strands[1].sequence == "AAATTT" assert system.strands[2].sequence == "TATATA" print(system) print(system.dataframe) # system.write_oxDNA() return
def test_Nucleotide_transform(): nucleotide = Nucleotide( "A", np.array([1.0, 0.0, 0.0]), np.array([1.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0]), ) nucleotide.translate(np.array([10., 0., 0.])) assert all(nucleotide.pos_com == [11., 0., 0.]) nucleotide.rotate([0., 0., 0., 1.]) nucleotide.rotate([0., 0., 0.]) nucleotide.rotate(np.array([ [1., 0., 0.], [0., 1., 0.], [0., 0., 0.], ])) nucleotide.transform( np.array([ [1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], ])) return