def rpoly_to_oxDNA(opts): # Read File # 'data' stores helix coordinates + rotaion in quaternion data = [] rev_helix_connections = [] # staple connection information, fwd_helix_connections = [] # scaffold connections count = 0 polyFile = open(opts.file_name_in, 'r') try: for line in polyFile: if line.startswith('hb'): data.insert(count, line.split(' ')) count += 1 elif line.startswith('c'): if 'f3' not in line: rev_helix_connections.append([ int(re.search('c helix_(.+?) ', line).group(1)), int(re.search('\' helix_(.+?) ', line).group(1)) ]) # Extract connection information else: fwd_helix_connections.append([ int(re.search('c helix_(.+?) ', line).group(1)), int(re.search('\' helix_(.+?) ', line).group(1)) ]) except Exception: print('Failed to read the file') generator = cu.StrandGenerator() staple_fragments = base.System( [100, 100, 100] ) # temporary system to store staple fragments before later connecting them scaffold_fragments = base.System([100, 100, 100]) # Reads orientation from the "data" and produces rotations from the Quaternian coordinates largest_size = 0.0 for n, i in enumerate(data): position = [ float(i[3]) / 0.84, float(i[4]) / 0.84, float(i[5]) / 0.84 ] # 0.84 scaling is ad hoc solution to get good looking models n_bp = int(i[2]) q = Quaternion(w=float(i[9]), x=float(i[6]), y=float(i[7]), z=float(i[8])) # find the helix roation Info from file vec = q.rotate(np.array([0.0, 0.0, 1.0])) # use it to figure out direction vec2 = q.rotate( [0.65, -0.76, 0.0]) # ad hoc onversion between rpoly rotation and cadnano utils new_position = move_along_vector( position, vec, n_bp ) # rpoly helix coordinates are defined in center of helix, cadnano utils have positions in the base of helix. for j in new_position: # go through every coordinate to find the largest coordinate to figure out box size if j > largest_size: largest_size = j else: pass # strand 0 is the scaffold and strand 1 is the staple new_strands = generator.generate_or_sq(bp=n_bp, start_pos=new_position, direction=vec, perp=vec2) fragment1, fragment2 = new_strands[1].cut_in_two( ) # cut strand 1 into two equal lengh staple fragments for later connections # store the fragments in this system for later connections staple_fragments.add_strand(fragment1) staple_fragments.add_strand(fragment2) scaffold_fragments.add_strand(new_strands[0]) output_system = base.System( [largest_size * 3.0, largest_size * 3.0, largest_size * 3.0]) for n in rev_helix_connections: # iterate through staple strand connections and connect the previously generated fragments connect_from = n[0] * 2 - 1 connect_to = n[1] * 2 - 2 staple_strand = staple_fragments._strands[connect_from].copy() staple_strand = staple_strand.append( staple_fragments._strands[connect_to].copy()) output_system.add_strand(staple_strand) scaffold_strand = scaffold_fragments._strands[0].copy() for n in fwd_helix_connections[:-1]: next_segment_adress = n[1] - 1 next_segment = scaffold_fragments._strands[next_segment_adress].copy() scaffold_strand = scaffold_strand.append(next_segment) scaffold_strand.make_circular() output_system.add_strand(scaffold_strand) basename = os.path.basename(opts.file_name_in) top_file = basename + ".top" conf_file = basename + ".oxdna" output_system.print_lorenzo_output(conf_file, top_file)
vhelix_counter = 0 if not side: side = cadsys.bbox() base.Logger.log( "Using default box size, a factor %s larger than size of cadnano system" % str(BOX_FACTOR), base.Logger.INFO) vhelix_direction_initial = np.array([0., 0., 1.]) vhelix_perp_initial = np.array([1., 0., 0.]) if origami_sq: vhelix_perp_initial = vhelix_rotation_origami_sq( vhelix_direction_initial, vhelix_perp_initial) elif origami_he: vhelix_perp_initial = vhelix_rotation_origami_he( vhelix_direction_initial, vhelix_perp_initial) slice_sys = base.System([side, side, side]) final_sys = base.System([side, side, side]) strand_number = -1 partner_list_scaf = [] partner_list_stap = [] found_partner = False join_list_scaf = [] join_list_stap = [] begin_helix = -1 end_helix = -1 for h in cadsys.vhelices: h.cad_index = vhelix_counter if origami_sq: strands, helix_angles, pos, rot, vhelix_direction, vhelix_perp = generate_vhelices_origami_sq( vhelix_direction_initial, vhelix_perp_initial, h, sequence_file, single_strand_system, vhelix_counter)
box_low = np.array([1e6, 1e6, 1e6], dtype=np.float64) box_high = np.array([-1e6, -1e6, -1e6], dtype=np.float64) for nucl in itertools.chain(*pdb_strands): com = nucl.get_com() for i in range(3): if com[i] < box_low[i]: box_low[i] = com[i] elif com[i] > box_high[i]: box_high[i] = com[i] L = 2 * np.max(box_high - box_low) * FROM_ANGSTROM_TO_OXDNA box = np.array([L, L, L]) print >> sys.stderr, "Using a box of size %g in oxDNA units (twice as big as the PDB bounding box size)" % (L) system = base.System(box) strand = base.Strand() for pdb_strand in pdb_strands: strand = base.Strand() for nucl in pdb_strand: nucl.compute_as() com = nucl.get_com() * FROM_ANGSTROM_TO_OXDNA new_oxDNA_nucl = base.Nucleotide(com, nucl.a1, nucl.a3, nucl.base[0]) strand.add_nucleotide(new_oxDNA_nucl) system.add_strand(strand, check_overlap=False) basename = os.path.basename(pdb_file)