VMD-L Mailing List
From: Giacomo Fiorin (giacomo.fiorin_at_gmail.com)
Date: Mon Jan 13 2025 - 15:42:26 CST
- Next message: Stipe Mustać: "Using python interpreter in VMD"
- Previous message: Nakshatra Upadhyay: "Applying electric field only on ions"
- In reply to: Nakshatra Upadhyay: "Applying electric field only on ions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Hi Nakshatra, do you have "tclForces on" before your first "run" command?
FYI, gridForces also allows you to specify a completely custom field, for
which you can also specify "charges" that are not necessarily equal to
those of the topology:
https://www.ks.uiuc.edu/Research/namd/3.0.1/ug/node43.html
The caveat is having to produce a 3D grid for your potential, but you get
full control of what you want with it and it would likely be faster than
tclForces.
Giacomo
On Mon, Jan 13, 2025 at 4:00 PM Nakshatra Upadhyay <
1225nakshatraupadhyay1975_at_gmail.com> wrote:
> Dear all,
> I want to perform an applied electric field simulation of a system
> consisting of a transmembrane channel. I want to apply the electric field
> only on the ions, i.e., potassium and chloride. I understand that I have to
> use tclforce option for that.
>
>
> I tried to write the following code, but it showed
> FATAL ERROR: Setting parameter tclForces from script failed!
>
> "
> tclForcesScript {
> # Parameters for the electric field
> set efield {0.0 0.0 0.603393} ;# Electric field in kcal/mol·Å·e
>
> # Atom selection: Read target atoms from the PDB file
> set targetMark "1.00"
> set targetAtomPdb "KCl.pdb"
> set targets {}
> set atoms {}
>
> # Open and process the PDB file
> set inStream [open $targetAtomPdb r]
> foreach line [split [read $inStream] \n] {
> if {([string equal [string range $line 0 4] "ATOM"] || \
> [string equal [string range $line 0 4] "HETA"]) && \
> [string equal [string trim [string range $line 54 59]]
> $targetMark]} {
> set segname [string trim [string range $line 72 75]]
> set resid [string trim [string range $line 22 25]]
> set atomname [string trim [string range $line 12 15]]
> lappend targets "$segname $resid $atomname"
> }
> }
> close $inStream
>
> # Convert targets to atom indices
> foreach target $targets {
> foreach {segname resid atomname} $target { break }
> set atomIndex [atomid $segname $resid $atomname]
> lappend atoms $atomIndex
> addatom $atomIndex
> }
>
> # Check if any atoms were selected
> if {[llength $atoms] == 0} {
> print "ERROR: No target atoms detected."
> return
> }
>
> # Procedure to apply electric field forces
> proc calcforces { } {
> global atoms efield
>
> # Extract electric field components
> foreach {ex ey ez} $efield { break }
>
> # Apply force to each atom
> foreach atom $atoms {
> set charge [atom charge $atom]
> set Fx [expr $charge * $ex]
> set Fy [expr $charge * $ey]
> set Fz [expr $charge * $ez]
> addforce $atom $Fx $Fy $Fz
> }
> }
>
> # Register the force calculation procedure
> runforces calcforces
> }
> "
> Could you please advise me on how to proceed?
> Best regards,
> Nakshatra
>
>
- Next message: Stipe Mustać: "Using python interpreter in VMD"
- Previous message: Nakshatra Upadhyay: "Applying electric field only on ions"
- In reply to: Nakshatra Upadhyay: "Applying electric field only on ions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]