From: Maxim Belkin (mbelkin_at_ks.uiuc.edu)
Date: Mon Feb 08 2016 - 11:24:47 CST

No problem.

> On Feb 8, 2016, at 11:07, Irem Altan <irem.altan_at_duke.edu> wrote:
>
> Thank you!
>
>> On Feb 8, 2016, at 11:57 AM, Maxim Belkin <mbelkin_at_ks.uiuc.edu <mailto:mbelkin_at_ks.uiuc.edu>> wrote:
>>
>> Simply pass them as arguments. Assuming that your "test" variable is not changing, you can do:
>>
>> source readedm.tcl
>> set test "test_115.xplor"
>>
>> proc analyze {} {
>> global test
>>
>> set mol [mol new]
>> readedm $test
>> mol addrep $mol
>> mol modstyle 0 $mol Isosurface 0.300000 0 2 1 1 1
>> mol modcolor 0 $mol ColorID 0
>>
>> return $mol
>> }
>>
>> proc cleanup {molecule} {
>> mol delete $molecule
>> }
>>
>> Then, wherever you use "analyze" and "cleanup", you would do:
>>
>> set x [analyze]
>> ...
>> cleanup $x
>>
>>
>> Alternatively, you can use global variables (similar to "test"), or upvar.
>> But I think that the solution above should suffice your needs.
>>
>>
>>
>>
>>
>>> On Feb 8, 2016, at 10:49, Irem Altan <irem.altan_at_duke.edu <mailto:irem.altan_at_duke.edu>> wrote:
>>>
>>> Thanks. I realized I was (quite stupidly) overlooking the fact that all the below lines except for mol delete $mol are in a procedure. So the code looks like this:
>>>
>>> proc analyze {} {
>>> set test "test_115.xplor"
>>> source readedm.tcl
>>>
>>> set mol [mol new]
>>> readedm $test
>>> mol addrep $mol
>>> mol modstyle 0 $mol Isosurface 0.300000 0 2 1 1 1
>>> mol modcolor 0 $mol ColorID 0
>>> }
>>>
>>> proc cleanup {} {
>>> mol delete $mol
>>> }
>>>
>>> I tried to make the variables global variables by adding the line global mol right before proc analyze. It still didn’t work, however. What is the best way to communicate the $mol variable between the two procedures?
>>>
>>>> On Feb 8, 2016, at 11:28 AM, Maxim Belkin <mbelkin_at_ks.uiuc.edu <mailto:mbelkin_at_ks.uiuc.edu>> wrote:
>>>>
>>>> I don’t see any significant problem here so molecule deletion should work just fine. However, in the script you refer to the molecule using "top" (mol addrep top) and numbers (second number in mol modstyle and mol modcolor). The correct way to write it would be:
>>>>
>>>> set test "test_115.xplor"
>>>> source readedm.tcl
>>>>
>>>> set mol [mol new]
>>>> readedm $test
>>>> mol addrep $mol
>>>> mol modstyle 0 $mol Isosurface 0.300000 0 2 1 1 1
>>>> mol modcolor 0 $mol ColorID 0
>>>> mol delete $mol
>>>>
>>>> Here indentation is for visual purposes only.
>>>>
>>>> Now, in the "readedm.tcl" they use "top" molecule which is fine in your case as long as you don’t add/delete molecules after "mol new" and before "readedm $test".
>>>>
>>>>
>>>>
>>>>> On Feb 8, 2016, at 10:16, Irem Altan <irem.altan_at_duke.edu <mailto:irem.altan_at_duke.edu>> wrote:
>>>>>
>>>>> Below is the relevant part of the code:
>>>>>
>>>>>
>>>>> set test “test_115.xplor”
>>>>>
>>>>> source readedm.tcl
>>>>>
>>>>> set molnum1 [mol new]
>>>>> readedm $test
>>>>> mol addrep top
>>>>> mol modstyle 0 0 Isosurface 0.300000 0 2 1 1 1
>>>>> mol modcolor 0 0 ColorID 0
>>>>>
>>>>> mol delete $molnum1
>>>>>
>>>>>
>>>>> where readedm.tcl is http://www.ks.uiuc.edu/Research/vmd/script_library/scripts/readedm/readedm.tcl <http://www.ks.uiuc.edu/Research/vmd/script_library/scripts/readedm/readedm.tcl>
>>>>>
>>>>> I now realize that had I been creating the variables correctly, mol modstyle 0 etc. should not have worked.
>>>>>
>>>>>> On Feb 8, 2016, at 11:05 AM, Maxim Belkin <mbelkin_at_ks.uiuc.edu <mailto:mbelkin_at_ks.uiuc.edu>> wrote:
>>>>>>
>>>>>> Please post the relevant part of the script you use. You are apparently making a mistake in there and it’s hard to help you without knowing what exactly you are doing.
>>>>>>
>>>>>> The error message says that you are trying to do something like:
>>>>>>
>>>>>> mol delete $variable
>>>>>>
>>>>>> where variable = molnum$molnum
>>>>>>
>>>>>> However, you should be doing:
>>>>>>
>>>>>> mol delete $molnum
>>>>>>
>>>>>> where molnum is 0, 1, 2, 3... and not molnum0, molnum1, molnum2,...
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> On Feb 8, 2016, at 09:55, Irem Altan <irem.altan_at_duke.edu <mailto:irem.altan_at_duke.edu>> wrote:
>>>>>>>
>>>>>>> Thanks for the answer. I can create the variables and load molecular data just fine, but when I do mol delete $molnum, I get the error "can't read “molnum1": no such variable”. mol delete 0, however, works.
>>>>>>>
>>>>>>>> On Feb 8, 2016, at 10:34 AM, Maxim Belkin <mbelkin_at_ks.uiuc.edu <mailto:mbelkin_at_ks.uiuc.edu>> wrote:
>>>>>>>>
>>>>>>>> set molnum [mol new]
>>>>>>>> ...
>>>>>>>> mol delete $molnum
>>>>>>>>
>>>>>>>>
>>>>>>>> On 02/08/2016 09:02 AM, Irem Altan wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I am reading data into molecules via a .tcl script, and then I eventually remove them:
>>>>>>>>>
>>>>>>>>> mol new
>>>>>>>>> …
>>>>>>>>> mol delete 0
>>>>>>>>>
>>>>>>>>> Now if I want to read in an extra molecule, its number becomes 1, despite the fact that 0 doesn’t exist anymore. Is there a way for me to set the number to 0? If not, how can I check within my script automatically what the next number will be?
>>>>>>>>>
>>>>>>>>> Best,
>>>>>>>>> Irem
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>