<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Daniel,<div class=""><span class="Apple-tab-span" style="white-space:pre">      </span>The ‘combine’ function doesn’t add the created Molecule to chimera.openModels.  You would have to do that yourself with chimera.openModels.add().  Without having added ‘combination' to openModels, openModels.remove(combination) is a no-op, and therefore the C++ memory being used by the Molecule is not reclaimed.  You either have to use openModels.add() or you have to explicitly reclaim the C++ memory with combination.destroy().</div><div class=""><br class=""></div><div class="">—Eric</div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">    </span>Eric Pettersen</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">  </span>UCSF Computer Graphics Lab</div></div><br class="Apple-interchange-newline">

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Oct 4, 2018, at 6:51 AM, Daniel VH <<a href="mailto:dviladrich95@gmail.com" class="">dviladrich95@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi, In my python script I'm using the combine() function to merge a protein and a molecule into one model and since I'm doing this multiple times and only use the combined result to save it with pdbWrite I want to free the memory of the object combination right after that, but after the instructions chimera.openModels.close(combination), del combination, chimera.update.checkForChanges(), gc.collect(), chimera.closeSession() the memory is not freed. This is the code that reproduces the problem, it uses the molecules in the zipfile I have attatched.<div class=""><br class=""></div><div class=""><div class="">import chimera</div><div class="">from Combine import combine</div><div class="">import zipfile</div><div class="">import time </div><div class="">import gc</div><div class="">import os </div><div class="">#from memory_profiler import profile</div><div class=""><br class=""></div><div class="">for itemnum in range(3):</div><div class=""><span style="white-space:pre-wrap" class="">      </span>#@profile</div><div class=""><span style="white-space:pre-wrap" class="">  </span>def pathmaker(itemnum):</div><div class=""><span style="white-space:pre-wrap" class="">            </span>dirpath = os.path.dirname(os.path.realpath(__file__))</div><div class=""><span style="white-space:pre-wrap" class="">              </span>zippath=dirpath+'/'+'test1_000.zip'</div><div class=""><span style="white-space:pre-wrap" class="">                </span>torsionpath=zipfile.ZipFile(zippath).extract('Pathway_000_Pathway.txt')</div><div class=""><span style="white-space:pre-wrap" class="">            </span>proteinpath=zipfile.ZipFile(zippath).extract('Protein_000_Protein.mol2')</div><div class=""><span style="white-space:pre-wrap" class="">           </span>ligandpath=zipfile.ZipFile(zippath).extract('Ligand_000_Ligand.mol2')</div><div class=""><br class=""></div><div class=""><span style="white-space:pre-wrap" class="">               </span>opened = chimera.openModels.open(proteinpath)</div><div class=""><span style="white-space:pre-wrap" class="">              </span>protein = opened[0]</div><div class=""><span style="white-space:pre-wrap" class="">                </span>opened1 = chimera.openModels.open(ligandpath)</div><div class=""><span style="white-space:pre-wrap" class="">              </span>mol=opened1[0]</div><div class=""><span style="white-space:pre-wrap" class="">             </span>combination=combine([mol,protein],protein)</div><div class=""><span style="white-space:pre-wrap" class="">         </span>totalnum=str(itemnum).zfill(3)+'_'+str(i).zfill(3)</div><div class=""><span style="white-space:pre-wrap" class="">         </span>chimera.pdbWrite([combination], chimera.Xform(), 'testpdb%s.pdb' %totalnum)</div><div class=""><span style="white-space:pre-wrap" class="">                </span>print('writing testpdb%s.pdb' %totalnum)</div><div class=""><span style="white-space:pre-wrap" class="">           </span>chimera.openModels.close(combination)</div><div class=""><span style="white-space:pre-wrap" class="">              </span>del combination</div><div class=""><span style="white-space:pre-wrap" class="">            </span>chimera.update.checkForChanges() </div><div class=""><span style="white-space:pre-wrap" class="">             </span>gc.collect()</div><div class=""><span style="white-space:pre-wrap" class="">               </span>chimera.closeSession()</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><span style="white-space:pre-wrap" class="">       </span>for i in range(20):</div><div class=""><span style="white-space:pre-wrap" class="">                </span>pathmaker(itemnum)</div><div class=""><span style="white-space:pre-wrap" class=""> </span>#this stops the code and shows memory increase for each iteration</div><div class=""><span style="white-space:pre-wrap" class="">  </span>print('pause 6 seconds...')</div><div class=""><span style="white-space:pre-wrap" class="">        </span>time.sleep(6)</div></div></div>
<span id="cid:1663f58c1318c2b8ea72"><testing.py></span><span id="cid:1663f591c90ddf088031"><test1_000.zip></span>_______________________________________________<br class="">Chimera-dev mailing list<br class=""><a href="mailto:Chimera-dev@cgl.ucsf.edu" class="">Chimera-dev@cgl.ucsf.edu</a><br class="">http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev<br class=""></div></blockquote></div><br class=""></div></body></html>