Exemple #1
0
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
Exemple #2
0
def with_strands(N: int = 10):
    a1 = np.array([1., 0., 0.])
    start = np.array([0., 0., 0.]) + a1 * 0.6
    direction = np.array([0., 1., 0.])
    strands = generate_helix(
        n=N,
        start_position=start,
        direction=direction,
        a1=a1,
        initial_rotation=0.0,
    )
    new_position = start + (N) * 0.39 * direction
    new_direction = np.array([0.0, 1.0, 1.0]) / 2**0.5
    new_a1 = np.array([0.0, -1.0, 1.0]) / 2**0.5
    #print(np.dot(new_a1, new_direction))
    rotation = -0.06
    #rotation = 0.0

    strands += generate_helix(
        n=N,
        start_position=new_position,
        direction=new_direction,
        a1=new_a1,
        initial_rotation=rotation,
    )
    strand = Strand(strands[0].nucleotides + strands[1].nucleotides)
    return [strand]
Exemple #3
0
def generate_system(box: np.ndarray) -> System:
    """Generate a simple oxDNA system"""
    system = System(box)
    strand = generate_helix(40, double=False)[0]
    new = []
    for nt in strand.nucleotides[10:30]:
        new.append(nt.make_across())
    new = Strand(nucleotides=new[::-1])
    system.add_strands([strand, new])    
    return system
Exemple #4
0
def generate_system(n: int, double_strand_length: int,
                    single_strand_length: int) -> SystemWithFolder:
    """
    Generates an oxDNA system containing a single piece of DNA
    which has blocks of equal size of double-stranded portions
    and single-stranded portions.
    

    Parameters:
        n - number of nucleotides e.g. 100
        fraction_ds - fraction of double-strand DNA e.g. 0.5
    
    Returns:
        system - oxDNA system
    """
    # initialise system to comply with minimum image convention
    box = 2. * n * FENE_EPS
    print(f'Creating simulation system with box size: {box}')
    system = SystemWithFolder(np.array([box, box, box]))

    # create a list of strands, our main strand which we will use
    # and our complementary strand
    strands = generate_helix(n, double=True)

    # make a copy of the complementary strand and remove it
    # from the main list of strands
    second_strand = strands[1].copy()
    strands = strands[:1]

    # calculate how many portions there should be
    portion_size = double_strand_length + single_strand_length
    portions = n // portion_size
    print(f'Creating {portions} portions of total size: {portion_size}')

    # iterate over all portions, adding a new complementary
    # strand to the list of strands we will use
    for i in range(portions):
        # take the nucleotides from each portion and
        # create a new strand for each double-stranded part
        # of the portion
        start = portion_size * i
        end = start + double_strand_length
        nucleotides = second_strand.nucleotides[start:end]
        new_strand = Strand(nucleotides=nucleotides)
        strands.append(new_strand)

    # finally add the strands to the system and return
    # the system
    system.add_strands(strands)
    return system
Exemple #5
0
    def add_strand(self, addition: Strand, index: int = None):
        """
        Method to add strand(s) to the system

        Parameters:
            addition - accepted as Strand objects or a List of Strands
            index (default = None) - Strand will append to current system,
            otherwise Strand inserted at location given
                
        """

        try:
            assert isinstance(addition, Strand)
        except TypeError:
            raise TypeError(f"addition must be Strand but is {type(addition)}")

        try:
            if index == None:
                self._strands.append(addition.copy())
            else:
                self._strands.insert(index, addition.copy())
        except TypeError:
            raise TypeError("Index must an an integer")
Exemple #6
0
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
Exemple #7
0
def main(length=16, n_strands=10):
    # generate a strand
    strands = []
    strand = generate_helix(n=length, enforce_180=True)[0]
    strands.append(strand.copy())

    for i in range(n_strands - 1):

        last_nuc = strands[-1].nucleotides[-1]
        direction = -last_nuc._a3
        a1 = -last_nuc._a1

        # ensure the backbone position is FENE_LENGTH away from
        # the backbone position of the previous nucleotide
        start = last_nuc.pos_back + (FENE_LENGTH - POS_BACK) * a1
        # generate strand above that's going in opposite direction
        strand = generate_helix(
            n=length,
            start_position=start,
            direction=direction,
            a1=a1,
            enforce_180=True,
        )[0]
        strands.append(strand)

    # using the two previously created strands create a new strand that
    # we will add to the system
    nucleotides = []
    for strand in strands:
        nucleotides += strand.nucleotides
    strand = Strand(nucleotides=nucleotides)

    # create system and add the final completed strand
    system = System(np.array([50., 50., 50.]))
    system.add_strand(strand)
    system.write_oxDNA('turns_18nt')
    return system
Exemple #8
0
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
Exemple #9
0
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