o
    Rŀg"                     @   s*   d Z ddlZddlmZ G dd dZdS )z<Code handle loading mmtf-python into Biopython's structures.    N)StructureBuilderc                   @   sx   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )StructureDecoderzHClass to pass the data from mmtf-python into a Biopython data structure.c                 C   s
   d| _ dS )zInitialize the class. N)	this_typeself r   N/var/www/html/myenv/lib/python3.10/site-packages/Bio/PDB/mmtf/DefaultParser.py__init__   s   
zStructureDecoder.__init__c                 C   s2   t  | _| jj|d i | _i | _i | _d| _dS )a  Initialize the structure object.

        :param total_num_bonds: the number of bonds in the structure
        :param total_num_atoms: the number of atoms in the structure
        :param total_num_groups: the number of groups in the structure
        :param total_num_chains: the number of chains in the structure
        :param total_num_models: the number of models in the structure
        :param structure_id: the id of the structure (e.g. PDB id)

        )structure_idr   N)r   structure_builderinit_structurechain_index_to_type_mapchain_index_to_seq_mapchain_index_to_description_mapchain_counter)r   total_num_bondstotal_num_atomstotal_num_groupstotal_num_chainstotal_num_modelsr   r   r   r	   r      s   
zStructureDecoder.init_structurec              
   C   sJ   |dkrd}| j jt|t|||fd|||t||t|	 d dS )a  Create an atom object an set the information.

        :param atom_name: the atom name, e.g. CA for this atom
        :param serial_number: the serial id of the atom (e.g. 1)
        :param alternative_location_id: the alternative location id for the atom, if present
        :param x: the x coordinate of the atom
        :param y: the y coordinate of the atom
        :param z: the z coordinate of the atom
        :param occupancy: the occupancy of the atom
        :param temperature_factor: the temperature factor of the atom
        :param element: the element of the atom, e.g. C for carbon. According to IUPAC. Calcium  is Ca
        :param charge: the formal atomic charge of the atom

          f)serial_numberelementN)r   	init_atomstrnparrayupper)r   	atom_namer   alternative_location_idxyz	occupancytemperature_factorr   charger   r   r	   set_atom_info/   s   

zStructureDecoder.set_atom_infoc                 C   sf   | j j|d | j| j dkrd| _n| j| j dkrd| _n| j| j dkr*d| _|  jd7  _d	S )
zSet the chain information.

        :param chain_id: the asym chain id from mmCIF
        :param chain_name: the auth chain id from mmCIF
        :param num_groups: the number of groups this chain has

        )chain_idpolymerr   znon-polymerHwaterW   N)r   
init_chainr   r   r   )r   r*   
chain_name
num_groupsr   r   r	   set_chain_info[   s   
zStructureDecoder.set_chain_infoc                 C   s,   |D ]}|| j |< || j|< || j|< qdS )aP  Set the entity level information for the structure.

        :param chain_indices: the indices of the chains for this entity
        :param sequence: the one letter code sequence for this entity
        :param description: the description for this entity
        :param entity_type: the entity type (polymer,non-polymer,water)

        N)r   r   r   )r   chain_indicessequencedescriptionentity_type	chain_indr   r   r	   set_entity_infon   s
   	

z StructureDecoder.set_entity_infoc
           
      C   s0   |dkrd}| j d | j || j|| dS )aQ  Set the information for a group.

        :param group_name: the name of this group, e.g. LYS
        :param group_number: the residue number of this group
        :param insertion_code: the insertion code for this group
        :param group_type: a string indicating the type of group (as found in the chemcomp dictionary.
            Empty string if none available.
        :param atom_count: the number of atoms in the group
        :param bond_count: the number of unique bonds in the group
        :param single_letter_code: the single letter code of the group
        :param sequence_index: the index of this group in the sequence defined by the entity
        :param secondary_structure_type: the type of secondary structure used
            (types are according to DSSP and number to type mappings are defined in the specification)

        r   r   N)r   init_seginit_residuer   )
r   
group_namegroup_numberinsertion_code
group_type
atom_count
bond_countsingle_letter_codesequence_indexsecondary_structure_typer   r   r	   set_group_info|   s   
zStructureDecoder.set_group_infoc                 C   s   | j | dS )zSet the information for a model.

        :param model_id: the index for the model
        :param chain_count: the number of chains in the model

        N)r   
init_model)r   model_idchain_countr   r   r	   set_model_info   s   zStructureDecoder.set_model_infoc                 C   s   | j || dS )zSet the crystallographic information for the structure.

        :param space_group: the space group name, e.g. "P 21 21 21"
        :param unit_cell: an array of length 6 with the unit cell parameters in order: a, b, c, alpha, beta, gamma

        N)r   set_symmetry)r   space_group	unit_cellr   r   r	   set_xtal_info   s   zStructureDecoder.set_xtal_infoc                 C      dS )a  Set the header information.

        :param r_free: the measured R-Free for the structure
        :param r_work: the measure R-Work for the structure
        :param resolution: the resolution of the structure
        :param title: the title of the structure
        :param deposition_date: the deposition date of the structure
        :param release_date: the release date of the structure
        :param experimnetal_methods: the list of experimental methods in the structure

        Nr   )r   r_freer_work
resolutiontitledeposition_daterelease_dateexperimnetal_methodsr   r   r	   set_header_info       z StructureDecoder.set_header_infoc                 C   rN   )a}  Set the Bioassembly transformation information. A single bioassembly can have multiple transforms.

        :param bio_assembly_index: the integer index of the bioassembly
        :param input_chain_indices: the list of integer indices for the chains of this bioassembly
        :param input_transform: the list of doubles for  the transform of this bioassmbly transform.

        Nr   )r   bio_assembly_indexinput_chain_indicesinput_transformr   r   r	   set_bio_assembly_trans   rW   z'StructureDecoder.set_bio_assembly_transc                 C   rN   )z.Any functions needed to cleanup the structure.Nr   r   r   r   r	   finalize_structure   rW   z#StructureDecoder.finalize_structurec                 C   rN   )a#  Add bonds within a group.

        :param atom_index_one: the integer atom index (in the group) of the first partner in the bond
        :param atom_index_two: the integer atom index (in the group) of the second partner in the bond
        :param bond_order: the integer bond order

        Nr   r   atom_index_oneatom_index_two
bond_orderr   r   r	   set_group_bond   rW   zStructureDecoder.set_group_bondc                 C   rN   )a#  Add bonds between groups.

        :param atom_index_one: the integer atom index (in the structure) of the first partner in the bond
        :param atom_index_two: the integer atom index (in the structure) of the second partner in the bond
        :param bond_order: the bond order

        Nr   r]   r   r   r	   set_inter_group_bond   rW   z%StructureDecoder.set_inter_group_bondN)__name__
__module____qualname____doc__r
   r   r)   r3   r9   rE   rI   rM   rV   r[   r\   ra   rb   r   r   r   r	   r      s    ,%			r   )rf   numpyr   Bio.PDB.StructureBuilderr   r   r   r   r   r	   <module>   s   