
:>"^N:  ã               @   sš   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z Gd d „  d e ƒ Z Gd	 d
 „  d
 e ƒ Z d S)z&Atom class, used in Structure objects.é    N)ÚDisorderedEntityWrapper)ÚPDBConstructionWarning)ÚVector)Ú	IUPACDatac               @   s  e  Z d  Z d Z d 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 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/ d0 „  Z d1 d2 „  Z d3 d4 „  Z d5 d6 „  Z d7 d8 „  Z d9 d: „  Z d; d< „  Z  d= d> „  Z! d? d@ „  Z" dA dB „  Z# dC dD „  Z$ dE dF „  Z% dG dH „  Z& dI dJ „  Z' dK dL „  Z( dM dN „  Z) dO dP „  Z* dQ dR „  Z+ dS dT „  Z, d S)UÚAtoma  Define Atom class.

    The Atom object stores atom name (both with and without spaces),
    coordinates, B factor, occupancy, alternative location specifier
    and (optionally) anisotropic B factor and standard deviations of
    B factor and positions.
    Nc	       	      C   sû   d |  _  d |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d |  _ | |  _	 d |  _
 d |  _ d |  _ d |  _ | |  _ i  |  _ | sµ | | j ƒ  k sµ t | ƒ ‚ |  j | ƒ |  _ |  j ƒ  |  _ d d d d d d d	 d
 i |  _ d S)a:  Initialize Atom object.

        :param name: atom name (eg. "CA"). Note that spaces are normally stripped.
        :type name: string

        :param coord: atomic coordinates (x,y,z)
        :type coord: Numeric array (Float0, size 3)

        :param bfactor: isotropic B factor
        :type bfactor: number

        :param occupancy: occupancy (0.0-1.0)
        :type occupancy: number

        :param altloc: alternative location specifier for disordered atoms
        :type altloc: string

        :param fullname: full atom name, including spaces, e.g. " CA ". Normally
                         these spaces are stripped from the atom name.
        :type fullname: string

        :param element: atom element, e.g. "C" for Carbon, "HG" for mercury,
        :type element: uppercase string (or None if unknown)
        ÚANr   ÚNÚCAé   ÚCé   ÚOé   )ÚlevelÚparentÚnameÚfullnameÚcoordÚbfactorÚ	occupancyÚaltlocÚfull_idÚidÚdisordered_flagÚanisou_arrayÚsiguij_arrayÚsigatm_arrayÚserial_numberÚxtraÚupperÚAssertionErrorÚ_assign_elementÚelementÚ_assign_atom_massZmassÚ_sorting_keys)	Úselfr   r   r   r   r   r   r   r"   © r&   ú1/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/Atom.pyÚ__init__   s(    #																%zAtom.__init__c             C   s;   t  | t ƒ r3 |  j d d … | j d d … k St Sd S)zTest equality.r
   N)Ú
isinstancer   r   ÚNotImplemented)r%   Úotherr&   r&   r'   Ú__eq__\   s    $zAtom.__eq__c             C   s;   t  | t ƒ r3 |  j d d … | j d d … k St Sd S)zTest inequality.r
   N)r)   r   r   r*   )r%   r+   r&   r&   r'   Ú__ne__c   s    $zAtom.__ne__c             C   s´   t  | t ƒ r¬ |  j | j k r1 |  j | j k S|  j j |  j d ƒ } |  j j | j d ƒ } | | k rw | | k S|  j | j k r™ |  j | j k S|  j | j k Sn t Sd S)zTest greater than.é   N)r)   r   r   r$   Úgetr   r   r*   )r%   r+   Úorder_sÚorder_or&   r&   r'   Ú__gt__j   s    
zAtom.__gt__c             C   s´   t  | t ƒ r¬ |  j | j k r1 |  j | j k S|  j j |  j d ƒ } |  j j | j d ƒ } | | k rw | | k S|  j | j k r™ |  j | j k S|  j | j k Sn t Sd S)zTest greater or equal.r.   N)r)   r   r   r$   r/   r   r   r*   )r%   r+   r0   r1   r&   r&   r'   Ú__ge__z   s    
zAtom.__ge__c             C   s´   t  | t ƒ r¬ |  j | j k r1 |  j | j k  S|  j j |  j d ƒ } |  j j | j d ƒ } | | k rw | | k  S|  j | j k r™ |  j | j k  S|  j | j k  Sn t Sd S)zTest less than.r.   N)r)   r   r   r$   r/   r   r   r*   )r%   r+   r0   r1   r&   r&   r'   Ú__lt__Š   s    
zAtom.__lt__c             C   s´   t  | t ƒ r¬ |  j | j k r1 |  j | j k S|  j j |  j d ƒ } |  j j | j d ƒ } | | k rw | | k S|  j | j k r™ |  j | j k S|  j | j k Sn t Sd S)zTest less or equal.r.   N)r)   r   r   r$   r/   r   r   r*   )r%   r+   r0   r1   r&   r&   r'   Ú__le__š   s    
zAtom.__le__c             C   s   t  |  j ƒ  ƒ S)zReturn atom full identifier.)ÚhashÚget_full_id)r%   r&   r&   r'   Ú__hash__«   s    zAtom.__hash__c             C   sï   | s | j  ƒ  t j k rë |  j d j ƒ  r[ |  j d d … j ƒ  r[ |  j j ƒ  } n0 |  j d j ƒ  r~ |  j d } n |  j d } | j  ƒ  t j k r¿ d | |  j | f } | } n d | |  j | f } d } t j	 | t
 ƒ | S)z9Guess element from atom name if not recognised (PRIVATE).r   r   Nr
   z8Used element %r for Atom (name=%s) with given element %rzDCould not assign element %r for Atom (name=%s) with given element %rÚ )Ú
capitalizer   Úatom_weightsr   ÚisalphaÚisdigitr   ÚstripÚwarningsÚwarnr   )r%   r"   Zputative_elementÚmsgr&   r&   r'   r!   ¯   s"    -
	zAtom._assign_elementc             C   s+   |  j  r t j |  j  j ƒ  St d ƒ Sd S)zReturn atom weight (PRIVATE).ÚNaNN)r"   r   r;   r:   Úfloat)r%   r&   r&   r'   r#   Ñ   s    	zAtom._assign_atom_massc             C   s   d |  j  ƒ  S)z&Print Atom object as <Atom atom_name>.z	<Atom %s>)Úget_id)r%   r&   r&   r'   Ú__repr__Û   s    zAtom.__repr__c             C   s)   |  j  | j  } t j t j | | ƒ ƒ S)zôCalculate distance between two atoms.

        :param other: the other atom
        :type other: L{Atom}

        Examples
        --------
        This is an incomplete but illustrative example::

            distance = atom1 - atom2

        )r   ÚnumpyÚsqrtÚdot)r%   r+   Zdiffr&   r&   r'   Ú__sub__ß   s    zAtom.__sub__c             C   s   | |  _  d S)zSet serial number.N)r   )r%   Únr&   r&   r'   Úset_serial_numberñ   s    zAtom.set_serial_numberc             C   s   | |  _  d S)zSet isotroptic B factor.N)r   )r%   r   r&   r&   r'   Úset_bfactorõ   s    zAtom.set_bfactorc             C   s   | |  _  d S)zSet coordinates.N)r   )r%   r   r&   r&   r'   Ú	set_coordù   s    zAtom.set_coordc             C   s   | |  _  d S)z#Set alternative location specifier.N)r   )r%   r   r&   r&   r'   Ú
set_altlocý   s    zAtom.set_altlocc             C   s   | |  _  d S)zSet occupancy.N)r   )r%   r   r&   r&   r'   Úset_occupancy  s    zAtom.set_occupancyc             C   s   | |  _  d S)a@  Set standard deviation of atomic parameters.

        The standard deviation of atomic parameters consists
        of 3 positional, 1 B factor and 1 occupancy standard
        deviation.

        :param sigatm_array: standard deviations of atomic parameters.
        :type sigatm_array: Numeric array (length 5)
        N)r   )r%   r   r&   r&   r'   Ú
set_sigatm  s    
zAtom.set_sigatmc             C   s   | |  _  d S)zÏSet standard deviations of anisotropic temperature factors.

        :param siguij_array: standard deviations of anisotropic temperature factors.
        :type siguij_array: Numeric array (length 6)
        N)r   )r%   r   r&   r&   r'   Ú
set_siguij  s    zAtom.set_siguijc             C   s   | |  _  d S)z‹Set anisotropic B factor.

        :param anisou_array: anisotropic B factor.
        :type anisou_array: Numeric array (length 6)
        N)r   )r%   r   r&   r&   r'   Ú
set_anisou  s    zAtom.set_anisouc             C   s   d |  _  d S)ztSet the disordered flag to 1.

        The disordered flag indicates whether the atom is disordered or not.
        r
   N)r   )r%   r&   r&   r'   Úflag_disorder#  s    zAtom.flag_disorderc             C   s   |  j  S)z:Return the disordered flag (1 if disordered, 0 otherwise).)r   )r%   r&   r&   r'   Úis_disordered*  s    zAtom.is_disorderedc             C   s   | |  _  |  j ƒ  |  _ d S)zXSet the parent residue.

        Arguments:
         - parent - Residue object

        N)r   r7   r   )r%   r   r&   r&   r'   Ú
set_parent.  s    	zAtom.set_parentc             C   s   d |  _  d S)zRemove reference to parent.N)r   )r%   r&   r&   r'   Údetach_parent8  s    zAtom.detach_parentc             C   s   |  j  S)z/Return standard deviation of atomic parameters.)r   )r%   r&   r&   r'   Ú
get_sigatm<  s    zAtom.get_sigatmc             C   s   |  j  S)z>Return standard deviations of anisotropic temperature factors.)r   )r%   r&   r&   r'   Ú
get_siguij@  s    zAtom.get_siguijc             C   s   |  j  S)zReturn anisotropic B factor.)r   )r%   r&   r&   r'   Ú
get_anisouD  s    zAtom.get_anisouc             C   s   |  j  S)zReturn parent residue.)r   )r%   r&   r&   r'   Ú
get_parentH  s    zAtom.get_parentc             C   s   |  j  S)zReturn the serial number.)r   )r%   r&   r&   r'   Úget_serial_numberL  s    zAtom.get_serial_numberc             C   s   |  j  S)zReturn atom name.)r   )r%   r&   r&   r'   Úget_nameP  s    zAtom.get_namec             C   s   |  j  S)z3Return the id of the atom (which is its atom name).)r   )r%   r&   r&   r'   rD   T  s    zAtom.get_idc             C   s    |  j  j ƒ  |  j |  j f f S)z Return the full id of the atom.

        The full id of an atom is the tuple
        (structure id, model id, chain id, residue id, atom name, altloc).
        )r   r7   r   r   )r%   r&   r&   r'   r7   X  s    zAtom.get_full_idc             C   s   |  j  S)zReturn atomic coordinates.)r   )r%   r&   r&   r'   Ú	get_coord`  s    zAtom.get_coordc             C   s   |  j  S)zReturn B factor.)r   )r%   r&   r&   r'   Úget_bfactord  s    zAtom.get_bfactorc             C   s   |  j  S)zReturn occupancy.)r   )r%   r&   r&   r'   Úget_occupancyh  s    zAtom.get_occupancyc             C   s   |  j  S)z<Return the atom name, including leading and trailing spaces.)r   )r%   r&   r&   r'   Úget_fullnamel  s    zAtom.get_fullnamec             C   s   |  j  S)z&Return alternative location specifier.)r   )r%   r&   r&   r'   Ú
get_altlocp  s    zAtom.get_altlocc             C   s   |  j  S)zReturn level.)r   )r%   r&   r&   r'   Ú	get_levelt  s    zAtom.get_levelc             C   s    t  j |  j | ƒ | |  _ d S)aH  Apply rotation and translation to the atomic coordinates.

        :param rot: A right multiplying rotation matrix
        :type rot: 3x3 Numeric array

        :param tran: the translation vector
        :type tran: size 3 Numeric array

        Examples
        --------
        This is an incomplete but illustrative example::

            from numpy import pi, array
            from Bio.PDB.vectors import Vector, rotmat
            rotation = rotmat(pi, Vector(1, 0, 0))
            translation = array((0, 0, 1), 'f')
            atom.transform(rotation, translation)

        N)rF   rH   r   )r%   ZrotZtranr&   r&   r'   Ú	transformx  s    zAtom.transformc             C   s"   |  j  \ } } } t | | | ƒ S)zvReturn coordinates as Vector.

        :return: coordinates as 3D vector
        :rtype: Bio.PDB.Vector class
        )r   r   )r%   ÚxÚyÚzr&   r&   r'   Ú
get_vectorŽ  s    zAtom.get_vectorc             C   sK   t  j  |  ƒ } | j ƒ  | j t  j  |  j ƒ  ƒ ƒ |  j j  ƒ  | _ | S)zHCreate a copy of the Atom.

        Parent information is lost.
        )ÚcopyrV   rM   r]   r   )r%   Zshallowr&   r&   r'   rh   —  s
    
z	Atom.copy)-Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r,   r-   r2   r3   r4   r5   r8   r!   r#   rE   rI   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   rD   r7   r]   r^   r_   r`   ra   rb   rc   rg   rh   r&   r&   r&   r'   r      sT   6"


	r   c               @   sF   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 S)ÚDisorderedAtoma×  Contains all Atom objects that represent the same disordered atom.

    One of these atoms is "selected" and all method calls not caught
    by DisorderedAtom are forwarded to the selected Atom object. In that way, a
    DisorderedAtom behaves exactly like a normal Atom. By default, the selected
    Atom object represents the Atom object with the highest occupancy, but a
    different Atom object can be selected by using the disordered_select(altloc)
    method.
    c             C   s   d |  _  t j |  | ƒ d S)zVCreate DisorderedAtom.

        Arguments:
         - id - string, atom name

        i?B NiÁ½ðÿ)Úlast_occupancyr   r(   )r%   r   r&   r&   r'   r(   ¯  s    	zDisorderedAtom.__init__c             c   s    x |  j  ƒ  D] } | Vq Wd S)z!Iterate through disordered atoms.N)Zdisordered_get_list)r%   Úir&   r&   r'   Ú__iter__¼  s    zDisorderedAtom.__iter__c             C   s   d |  j  ƒ  S)z"Return disordered atom identifier.z<Disordered Atom %s>)rD   )r%   r&   r&   r'   rE   Á  s    zDisorderedAtom.__repr__c             C   sn   | j  ƒ  |  j ƒ  } | j | ƒ | j ƒ  } | j ƒ  } | |  | <| |  j k rj | |  _ |  j | ƒ d S)zAdd a disordered atom.N)rS   rZ   rU   ra   r_   rn   Zdisordered_select)r%   ZatomZresiduer   r   r&   r&   r'   Údisordered_addÅ  s    

	zDisorderedAtom.disordered_addN)ri   rj   rk   rl   r(   rp   rE   rq   r&   r&   r&   r'   rm   ¤  s
   	rm   )rl   rF   r?   rh   ZBio.PDB.Entityr   ZBio.PDB.PDBExceptionsr   ZBio.PDB.vectorsr   ZBio.Datar   Úobjectr   rm   r&   r&   r&   r'   Ú<module>   s   ÿ ‘