ó
‚™xTc           @   s„   d  d l  m Z d  d l m Z m Z d  d l m Z d  d l Z d Z e j	 d „ Z
 d „  Z e d k r€ e
 e j d	 ƒ n  d S(
   iÿÿÿÿ(   t   division(   t   Sorryt   Usage(   t   parseStringNs8   
pdb_id = None
  .type = str
email = None
  .type = str
c      	      s/  t  |  ƒ d k s d |  k r- t d ƒ ‚ n  d d  l ‰  d d  l ‰  y d d l m } Wn t k
 rx t d ƒ ‚ n Xd ˆ  j j	 f ‡  f d †  ƒ  Y} | d	 |  d
 t
 d d ƒ } | j j ƒ  } t | ƒ ˆ  j j j d | j ƒ } d  } x\ | j ƒ  D]N } | j d ƒ rý | j ƒ  }	 |	 d d k rKt |	 d j ƒ  ƒ } PqKqý qý W| d  k rjt d ƒ ‚ n  | d | IJ| j | _ | j d d d t | ƒ d d d d ƒ }
 d „  } t |
 j ƒ  ƒ } | j d ƒ } t  | ƒ d k sðt ‚ | d } | j d ƒ } g  } xH | D]@ } | | d ƒ d d j | | d  ƒ ƒ d } | j | ƒ qWd j | d  ƒ d! | d } | | d" ƒ } | j  d ƒ s¤| d 7} n  | j d# ƒ d } | | d$ ƒ } | | d% ƒ } | | d& ƒ } | | d' ƒ } | d( | j! d) d* ƒ | | j! d) d* ƒ | | | f IJd  S(+   Ni    s   --helps÷   iotbx.pdb.get_citation ID EMAIL

Given a PDB ID (and an email address, as required by the NCBI), will attempt
to identify the PubMed ID of the primary citation for the structure, download
the article XML from NCBI, and print a bibliography entry.
iÿÿÿÿ(   t   Entrezs   BioPython not installed.t   _cmdlinec              s   e  Z ‡  f d  †  Z RS(   c            sV   ˆ  j  j j | ƒ r) ˆ  j j d | ƒ S| j d ƒ d k rR ˆ  j j d | ƒ St S(   Ns	   pdb_id=%st   @i   s
   email="%s"(   t   pdbt   fetcht   looks_like_pdb_idt   philt   parset   countt   False(   t   selft   arg(   t   iotbx(    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyt   process_other   s
    (   t   __name__t
   __module__R   (    (   R   (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyR      s   t   argst   master_phil_stringt   integer_deft   pmidt   idt   JRNLi   t   PMIDi   s&   Couldn't extract PMID from PDB header.s	   PMID = %st   dbt   pubmedt   rettypet   xmlt   retmodet   textc         S   s'   |  j  | ƒ } t | d j d j ƒ S(   Ni    (   t   getElementsByTagNamet   unicodet
   childNodest   data(   t   xml_nodet	   node_namet   child_nodes(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyt   get_node_data<   s    t   PubmedArticlet   Authort   LastNames   , t   .t   Initialss    & t   ArticleTitlet   PubDatet   Yeart	   MedlineTAt   Volumet
   MedlinePgns   %s (%s).  %s %s %s, %s.t   asciit   ignore("   t   lenR   t   iotbx.pdb.fetcht
   iotbx.philt   BioR   t   ImportErrorR   R
   t   process_command_line_with_filesR   t   workt   extractt   validate_paramsR   R   t   pdb_idt   Nonet	   readlinest
   startswitht   splitt   intt   stript   emailt   efetcht   strR   t   readR!   t   AssertionErrort   joint   appendt   endswitht   encode(   R   t   outR   R   t   cmdlinet   paramst   pdb_dataR   t   linet   fieldsR$   R(   t   xmlrect   articlest   articlet   authorst   author_listt   authort   namet   peoplet   titlet   datet   yeart   journalt   volumet   pages(    (   R   sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyt   run   sh    "	
!		
-!c         C   s@   |  j  d  k r t d ƒ ‚ n  |  j d  k r< t d ƒ ‚ n  t S(   Ns   PDB ID not specified!s"   Please give a valid email address.(   R?   R@   R   RF   t   True(   RQ   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyR>   X   s
    t   __main__i   (   t
   __future__R    t   libtbx.utilsR   R   t   xml.dom.minidomR   t   sysR   t   stdoutRc   R>   R   t   argv(    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_get_citation.pyt   <module>   s   I	