<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi all,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Following on from Graeme's email about .o files, another way to quite dramatically reduce the size of the distribution (with little impact on code complexity or performance) would be to keep all the various text-based data files in .zip format. With modern
 Python fetching the data from these is little different from working with uncompressed files anyway (1-2 extra lines of code, generally negligible runtime cost). A couple of snippets as an example from ISOLDE (where I keep all MD ligand definition files in
 a .zip):</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
To get a list of the file contents:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback';font-weight:normal;font-size:14px;line-height:19px">
<span><span>&nbsp; &nbsp; </span><span style="color:#569cd6">def</span><span>&nbsp;</span><span style="color:#dcdcaa">_ligand_db_from_zip</span><span>(</span><span style="color:#9cdcfe">self</span><span>,
</span><span style="color:#9cdcfe">ligand_zip</span><span>):</span></span>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">from</span><span>&nbsp;zipfile </span>
<span style="color:#c586c0">import</span><span>&nbsp;ZipFile</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">import</span><span>&nbsp;os</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; namelist = []</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">with</span><span>&nbsp;ZipFile(ligand_zip)
</span><span style="color:#c586c0">as</span><span>&nbsp;zf:</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">for</span><span>&nbsp;fname </span>
<span style="color:#c586c0">in</span><span>&nbsp;zf.namelist():</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name, ext = os.path.splitext(fname)</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">if</span><span>&nbsp;ext.lower() ==
</span><span style="color:#ce9178">'.xml'</span><span>:</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; namelist.append(name)</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">return</span><span>&nbsp;namelist</span></div>
</div>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
To read a given file from the zip as needed:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback';font-weight:normal;font-size:14px;line-height:19px">
<span><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">if</span><span>&nbsp;ligand_db </span>
<span style="color:#569cd6">is</span><span>&nbsp;</span><span style="color:#569cd6">not</span><span>&nbsp;</span><span style="color:#569cd6">None</span><span>:</span></span>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#dcdcaa">zip</span><span>, namelist = ligand_db</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">if</span><span>&nbsp;name </span>
<span style="color:#569cd6">in</span><span>&nbsp;namelist:</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">from</span><span>&nbsp;zipfile
</span><span style="color:#c586c0">import</span><span>&nbsp;ZipFile</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.info(</span><span style="color:#ce9178">'Loading residue template for
</span><span style="color:#569cd6">{}</span><span style="color:#ce9178">&nbsp;from internal database'</span><span>.format(name))</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">with</span><span>&nbsp;ZipFile(</span><span style="color:#dcdcaa">zip</span><span>)
</span><span style="color:#c586c0">as</span><span>&nbsp;zf:</span></div>
<div><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#c586c0">with</span><span>&nbsp;zf.open(name+</span><span style="color:#ce9178">'.xml'</span><span>)
</span><span style="color:#c586c0">as</span><span>&nbsp;xf:</span></div>
<span><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; forcefield.loadFile(xf)</span></span>
<div><span></span></div>
</div>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Even just doing this for the CaBLAM contour data cuts about 160 MB off the size of the uncompressed distribution.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Tristan<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>