Re: How to add a C code to NAMD properly?

From: Faramarz Joodaki (fjoodaki_at_my.uri.edu)
Date: Sun Dec 16 2018 - 11:59:19 CST

Hi everyone!

According to Haichuan's guidance, I am trying to do some runtime
calculations over a MD simulation by using Colvars. I would like to pass
two parameters of Colvars to a function in the NAMD configuration file to
apply my calculation on them. For example, the function in the NAMD
configuration file can be:

namespace eval funca { }
proc calc_funca {arg1 arg2} {...}

   - arg1 can be Cartesian coordinate
   - arg2 can be a distance

My question is how can I define these two variables in colvars at the same
time and pass them to a function in the NAMD configuration file?

Best Regards,
Faramarz

On Sun, Dec 16, 2018 at 12:50 PM Faramarz Joodaki <fjoodaki_at_my.uri.edu>
wrote:

> Dear Haochuan,
>
> Thank you for your guidance!
>
> Best Regards,
> Faramarz
>
> On Sat, Dec 15, 2018 at 8:33 PM <yjcoshc_at_gmail.com> wrote:
>
>> Dear Faramarz,
>>
>> Please copy the email to the NAMD mailing list. This may give hints for
>> other people who have the same question.
>>
>> As for your question, I am not very sure whether following code works:
>>
>> proc calc_funca {args} {
>>
>> set cartesian [lindex $args 0]
>>
>> set distance [lindex $args 1]
>>
>> }
>>
>> It may require some trying and debugging, but basically you can use puts
>> to output the args to stdout and see the format of arguments from NAMD log.
>>
>> Thanks,
>>
>> Haochuan Chen
>>
>> 在 2018年12月15日 09:05, Faramarz Joodaki 写道:
>>
>> Dear Haochuan,
>>
>> Thanks again for your help! I have another question. I would be so
>> grateful if you could guide me with this matter. How can I pass two or more
>> parameters from colvars to the function in NAMD configuration file. For
>> example:
>>
>> namespace eval funca { }
>> proc calc_funca {arg1 arg2} {...}
>>
>>
>> - arg1 can be cartesian coordinate
>> - arg2 can be a distance
>>
>>
>> Best Regards,
>> Faramarz
>>
>> On Sat, Dec 8, 2018 at 1:28 PM Faramarz Joodaki <fjoodaki_at_my.uri.edu>
>> wrote:
>>
>>> Dear Haochuan,
>>>
>>> Thank you very much for your complete explanation! So it seems that I
>>> need to use TCL syntax for this kind of scripting.
>>>
>>> Best Regards,
>>> Faramarz
>>>
>>> On Sat, Dec 8, 2018 at 6:55 AM <yjcoshc_at_gmail.com> wrote:
>>>
>>>> Hi Faramarz,
>>>>
>>>> In the NAMD configuration you can enable colvars and source this TCL
>>>> script:
>>>>
>>>> namespace eval funca { }
>>>> proc calc_funca {args} {
>>>> puts $args
>>>> set x0 [lindex [lindex $args 0] 0]
>>>> set y0 [lindex [lindex $args 0] 1]
>>>> set z0 [lindex [lindex $args 0] 2]
>>>> return [expr $x0 + $y0 + $z0]
>>>> }
>>>>
>>>> In the colvars file:
>>>>
>>>> colvar {
>>>> name a
>>>> scriptedFunction funca
>>>>
>>>> cartesian {
>>>> atoms {atomNumbers {5}}
>>>> }
>>>> }
>>>>
>>>> Then the x, y and z coordinates of the atom 5 will be added up and
>>>> outputted to the colvars trajectory file. A more comprehensive example is
>>>> in
>>>> https://github.com/Colvars/colvars/blob/master/colvartools/pathCV.tcl
>>>>
>>>> Regards,
>>>>
>>>> Haochuan Chen
>>>>
>>>> 在 2018年12月08日 10:56, Faramarz Joodaki 写道:
>>>>
>>>> Dear Haochuan,
>>>>
>>>> Thank you again for your great guidance! Since I am new in colvars and
>>>> scriptedFunction. I would be so grateful if you could give me an example
>>>> about this kind of scripting. For example, if we assume x, y, and z are
>>>> atom coordinates, how can we write x+y+z code in this kind of scripting?
>>>>
>>>> Best Regards,
>>>> Faramarz
>>>>
>>>> On Wed, Dec 5, 2018 at 8:51 PM Faramarz Joodaki <fjoodaki_at_my.uri.edu>
>>>> wrote:
>>>>
>>>>> Dear Haochuan,
>>>>>
>>>>> Thank you for your guidance! I will try your method and if I have any
>>>>> questions, I will ask you about that.
>>>>>
>>>>> Best Regards,
>>>>> Faramarz
>>>>>
>>>>> > On Dec 5, 2018, at 8:45 PM, yjcoshc <yjcoshc_at_gmail.com> wrote:
>>>>> >
>>>>> > Haochuan
>>>>>
>>>>
>>>>
>>

This archive was generated by hypermail 2.1.6 : Mon Dec 31 2018 - 23:21:36 CST