1<?php
2/*
3description : RCSB utility to access RCSB PDB
4author      : Ikuo Obataya
5email       : ikuo_obataya@symplus.co.jp
6lastupdate  : 2023-08-07
7license     : GPL 2 (http://www.gnu.org/licenses/gpl.html)
8*/
9if(!defined('DOKU_INC')) die();
10class rcsb{
11  var $HttpClient;
12  var $ImgURL;
13  var $LinkURL;
14  var $LinkFormat;
15  function __construct()
16  {
17    $this->HttpClient = new DokuHTTPClient();
18    $this->ImgURL     = 'http://www.rcsb.org/pdb/images/%s_bio_r_500.jpg';
19    $this->LinkURL    = 'http://www.rcsb.org/pdb/explore.do?structureId=%s';
20    $this->LinkFormat = '<a href="http://www.rcsb.org/pdb/explore.do?structureId=%s"><span class="%s">%s</span></a>';
21  }
22  /*
23   * Download protein image
24   */
25  function DownloadImage($pdbid,$path){
26    $pdbid = $this->PDBformat($pdbid);
27    if ($pdbid===false) return false;
28    if(!@file_exists($path)){
29      $downloadURL = sprintf($this->ImgURL,$pdbid);
30      io_download($downloadURL,$path);
31    }
32    return @file_exists($path);
33  }
34  /*
35   * Return URL of a specified protein
36   */
37  function ExplorerURL($pdbid){
38    $pdbid = $this->PDBformat($pdbid);
39    if ($pdbid===false) return false;
40    return sprintf($this->LinkURL,$pdbid);
41  }
42  /*
43   * Make a link for RCSB Explorer
44   */
45  function ExplorerLink($pdbid,$class="pdb_plugin_acc"){
46    $pdbid = $this->PDBformat($pdbid);
47    if ($pdbid===false) return false;
48    $class  = urlencode($class);
49    return sprintf($this->LinkFormat,$pdbid,$class,strtoupper($pdbid));
50  }
51
52  function PDBformat($pdbid){
53    $pdbid=strtolower(urlencode($pdbid));
54    if (strlen($pdbid)!=4) return false;
55    return $pdbid;
56  }
57}
58
59