<commit_before>##### namd_interface.py #####

import numpy as np
import re, os

from .file_io import read_xyz

# This is hardcoded for now
head_pattern = re.compile(r'CRYST')
first_atom_pattern = re.compile(r'LIT')
end_pattern = re.compile(r'END')


def read_pdb_snapshots(snapshot_dir_prefix):
   file_pattern = re.compile(r'snapshot(\d+)(\w*).(\w+)')
   snapshot_dir_ls = os.listdir(snapshot_dir_prefix)

   # Sort for the highest number
   snapshot_index_list = []
   for filename in snapshot_dir_ls:
      if file_pattern.search(filename):
         snapshot_index = eval(file_pattern.search(filename).group(1))
         snapshot_index_list.append(snapshot_index)

   num_snapshots = max(snapshot_index_list)

   # Actually reading the files. The list holds n numpy vectors.
   snapshots_coord_list = []
   snapshots_force_list = []

   for i in range(num_snapshots):
      coord_file_obj = open(os.path.join(snapshot_dir_prefix,'snapshot{0}.coord.xyz'.format(i+1)),'r')
      force_file_obj = open(os.path.join(snapshot_dir_prefix,'snapshot{0}.force.xyz'.format(i+1)),'r')

      coord_content = read_xyz(coord_file_obj)
      force_content = read_xyz(coord_file_obj)

      snapshots_coord_list.append(coord_content)
      snapshots_force_list.append(force_content)

      coord_file_obj.close()
      force_file_obj.close()

   return (snapshots_coord_list, snapshots_force_list)


def write_single_pdb(headline, frame_lines, count, pdb_type):
   if pdb_type == 'coord':
      file_obj = open('../results/snapshot{0}.pdb'.format(count), 'w')
   elif pdb_type == 'vel':
      file_obj = open('../results/snapshot{0}.vel'.format(count), 'w')

   file_obj.write(headline)
   for line in frame_lines:
      file_obj.write(line)

   file_obj.close()


def split_multiframe_pdb(pdb_file_obj, pdb_type):
   numframes = 1<commit_msg>[master 20170113 E10] 'namd_interface.py' (Rev. 4) Fixed force file reading<commit_after>##### namd_interface.py #####

import numpy as np
import re, os

from .file_io import read_xyz

# This is hardcoded for now
head_pattern = re.compile(r'CRYST')
first_atom_pattern = re.compile(r'LIT')
end_pattern = re.compile(r'END')


def read_pdb_snapshots(snapshot_dir_prefix):
   file_pattern = re.compile(r'snapshot(\d+)(\w*).(\w+)')
   snapshot_dir_ls = os.listdir(snapshot_dir_prefix)

   # Sort for the highest number
   snapshot_index_list = []
   for filename in snapshot_dir_ls:
      if file_pattern.search(filename):
         snapshot_index = eval(file_pattern.search(filename).group(1))
         snapshot_index_list.append(snapshot_index)

   num_snapshots = max(snapshot_index_list)

   # Actually reading the files. The list holds n numpy vectors.
   snapshots_coord_list = []
   snapshots_force_list = []

   for i in range(num_snapshots):
      coord_file_obj = open(os.path.join(snapshot_dir_prefix,'snapshot{0}.coord.xyz'.format(i+1)),'r')
      force_file_obj = open(os.path.join(snapshot_dir_prefix,'snapshot{0}.force.xyz'.format(i+1)),'r')

      coord_content = read_xyz(coord_file_obj)
      force_content = read_xyz(force_file_obj)

      snapshots_coord_list.append(coord_content)
      snapshots_force_list.append(force_content)

      coord_file_obj.close()
      force_file_obj.close()

   return (snapshots_coord_list, snapshots_force_list)


def write_single_pdb(headline, frame_lines, count, pdb_type):
   if pdb_type == 'coord':
      file_obj = open('../results/snapshot{0}.pdb'.format(count), 'w')
   elif pdb_type == 'vel':
      file_obj = open('../results/snapshot{0}.vel'.format(count), 'w')

   file_obj.write(headline)
   for line in frame_lines:
      file_obj.write(line)

   file_obj.close()


def split_multiframe_pdb(pdb_file_obj, pdb_type):
   numframes = 1
{'fraction_non_alphanumeric': 0.12406015037593984, 'fraction_numerical': 0.007250268528464017, 'mean_word_length': 4.414244186046512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1827982', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1305, 'n_words': 222}