<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PDB related functions used in the SCT suite of programs
"""

import seq

def pdb_res_line_parse(line):
    """Parse a single line from a PDB file into a dictionary according to
    the standard PDB column definitions

    @type  line: string
    @param line: Line from a PDB file.
    @rtype:      dictionary
    @return:     A dictionary containing:
                 - atom_no:   integer, atom number
                 - atom_name: string, atom name
                 - res_id:    string, residue three letter code
                 - chain:     string, chain identifier
                 - res_no:    integer, residue number
                 - coords:    list of floats, the x, y & z coordinates
    """

    data = {}

    # Only interested in ATOM and HETATM lines not REMARKs etc.
    # The type of record on the line is determined by the first 6 characters
    record = line[0:6].strip()
    if record in ['ATOM','HETATM']:

        # Split data on the line according to column definitions for PDB files
        # Ignore residues that we can't handle in SCT
        # TODO: This should perhaps give a warning

        # res_id is a three letter residue code
        res_id = line[17:20].strip()
        if res_id in sct_seq.all_residues:
            data['atom_no'] = int(line[6:11])
            data['atom_name'] = line[12:16].strip()
            data['res_id'] = res_id
            data['chain'] = line[21:22].strip()
            data['res_no'] = int(line[22:26])
            x = float(line[30:38])
            y = float(line[38:46])
            z = float(line[46:54])
            data['coords'] = [x, y, z]

    return data

def read_pdb_atom_data (filename):
    """
    Read PDB file and return residue ferquencies and atom coordinates

    @type  filename: string
    @param filename: Path to a PDB file.
    @rtype:   dictionary, list
    @return:  1. Dictionary for residue type frequency. Three letter residue
              code for the key and residue type frequency as the values.

              2. A list containing lists of x, y & z coordinates (3 * floats)
    """

    # Initialize a dictionary of all recognized residues (frequency = 0)
    res_freq = sct_seq.residue_freq_dict()

    # Track the last residues seen
    last_res_no = 0

    atom_coords = []

    # Read in lines of the PDB
    # ATOM and HETATM records are interpretted - others ignored
    with open(filename) as f:
        for line in f:<commit_msg>pdb.py: removed references to the old sct_seq naming of the sequence related module<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PDB related functions used in the SCT suite of programs
"""

import seq

def pdb_res_line_parse(line):
    """Parse a single line from a PDB file into a dictionary according to
    the standard PDB column definitions

    @type  line: string
    @param line: Line from a PDB file.
    @rtype:      dictionary
    @return:     A dictionary containing:
                 - atom_no:   integer, atom number
                 - atom_name: string, atom name
                 - res_id:    string, residue three letter code
                 - chain:     string, chain identifier
                 - res_no:    integer, residue number
                 - coords:    list of floats, the x, y & z coordinates
    """

    data = {}

    # Only interested in ATOM and HETATM lines not REMARKs etc.
    # The type of record on the line is determined by the first 6 characters
    record = line[0:6].strip()
    if record in ['ATOM','HETATM']:

        # Split data on the line according to column definitions for PDB files
        # Ignore residues that we can't handle in SCT
        # TODO: This should perhaps give a warning

        # res_id is a three letter residue code
        res_id = line[17:20].strip()
        if res_id in seq.all_residues:
            data['atom_no'] = int(line[6:11])
            data['atom_name'] = line[12:16].strip()
            data['res_id'] = res_id
            data['chain'] = line[21:22].strip()
            data['res_no'] = int(line[22:26])
            x = float(line[30:38])
            y = float(line[38:46])
            z = float(line[46:54])
            data['coords'] = [x, y, z]

    return data

def read_pdb_atom_data (filename):
    """
    Read PDB file and return residue ferquencies and atom coordinates

    @type  filename: string
    @param filename: Path to a PDB file.
    @rtype:   dictionary, list
    @return:  1. Dictionary for residue type frequency. Three letter residue
              code for the key and residue type frequency as the values.

              2. A list containing lists of x, y & z coordinates (3 * floats)
    """

    # Initialize a dictionary of all recognized residues (frequency = 0)
    res_freq = seq.residue_freq_dict()

    # Track the last residues seen
    last_res_no = 0

    atom_coords = []

    # Read in lines of the PDB
    # ATOM and HETATM records are interpretted - others ignored
    with open(filename) as f:
        for line in f:
{'fraction_non_alphanumeric': 0.0872827804107425, 'fraction_numerical': 0.01579778830963665, 'mean_word_length': 2.142059553349876, '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': '4954048', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1431, 'n_words': 563}