Example #1
0
            public static Vector[] GetRotate(Vector[] coords, Vector cent, int[] block)
            {
                throw new Exception("this implementation is wrong. Use the following algorithm to get rotation modes for RTB.");

                double[] io_mass = null;
                if (HDebug.IsDebuggerAttached)
                {
                    using (var temp = new HTempDirectory(@"K:\temp\", null))
                    {
                        temp.EnterTemp();
                        HFile.WriteAllText("rtbProjection.m", @"
function [P, xyz] = rtbProjection(xyz, mass)
% the approach is to find the inertia. compute the principal axes. and then use them to determine directly translation or rotation. 

n = size(xyz, 1); % n: the number of atoms
if nargin == 1
    mass = ones(n,1);
end

M = sum(mass);
% find the mass center.
m3 = repmat(mass, 1, 3);
center = sum (xyz.*m3)/M;
xyz = xyz - center(ones(n, 1), :);

mwX = sqrt (m3).*xyz;
inertia = sum(sum(mwX.^2))*eye(3) - mwX'*mwX;
[V,D] = eig(inertia);
tV = V'; % tV: transpose of V. Columns of V are principal axes. 
for i=1:3
    trans{i} = tV(ones(n,1)*i, :); % the 3 translations are along principal axes 
end
P = zeros(n*3, 6);
for i=1:3
    rotate{i} = cross(trans{i}, xyz);
    temp = mat2vec(trans{i});
    P(:,i) = temp/norm(temp);
    temp = mat2vec(rotate{i});
    P(:,i+3) = temp/norm(temp);
end
m3 = mat2vec(sqrt(m3));
P = repmat (m3(:),1,size(P,2)).*P;
% now normalize columns of P
P = P*diag(1./normMat(P,1));

function vec = mat2vec(mat)
% convert a matrix to a vector, extracting data *row-wise*.
vec = reshape(mat',1,prod(size(mat)));
");
                        Matlab.Execute("cd \'" + temp.dirinfo.FullName + "\'");
                        Matlab.PutMatrix("xyz", coords.ToMatrix(false));
                        Matlab.PutVector("mass", io_mass);
                        temp.QuitTemp();
                    }
                }

                HDebug.Assert(coords.Length == io_mass.Length);

                Vector mwcenter = new double[3];

                for (int i = 0; i < coords.Length; i++)
                {
                    mwcenter += (coords[i] * io_mass[i]);
                }
                mwcenter /= io_mass.Sum();

                Vector[] mwcoords = new Vector[coords.Length];
                for (int i = 0; i < coords.Length; i++)
                {
                    mwcoords[i] = (coords[i] - mwcenter) * io_mass[i];
                }

                Matrix mwPCA = new double[3, 3];

                for (int i = 0; i < coords.Length; i++)
                {
                    mwPCA += LinAlg.VVt(mwcoords[i], mwcoords[i]);
                }

                var V_D = LinAlg.Eig(mwPCA.ToArray());
                var V   = V_D.Item1;

                Vector[] rotvecs = new Vector[3];
                for (int i = 0; i < 3; i++)
                {
                    Vector   rotaxis = new double[] { V[0, i], V[1, i], V[2, i] };
                    Vector[] rotveci = new Vector[coords.Length];
                    for (int j = 0; j < coords.Length; j++)
                    {
                        rotveci[j] = LinAlg.CrossProd(rotaxis, mwcoords[i]);
                    }
                    rotvecs[i] = rotveci.ToVector().UnitVector();
                }

                if (HDebug.IsDebuggerAttached)
                {
                    double dot01 = LinAlg.VtV(rotvecs[0], rotvecs[1]);
                    double dot02 = LinAlg.VtV(rotvecs[0], rotvecs[2]);
                    double dot12 = LinAlg.VtV(rotvecs[1], rotvecs[2]);
                    HDebug.Assert(Math.Abs(dot01) < 0.0000001);
                    HDebug.Assert(Math.Abs(dot02) < 0.0000001);
                    HDebug.Assert(Math.Abs(dot12) < 0.0000001);
                }

                return(rotvecs);



                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                /// from song: rtbProjection.m
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                /// function [P, xyz] = rtbProjection(xyz, mass)
                /// % the approach is to find the inertia. compute the principal axes. and then use them to determine directly translation or rotation.
                ///
                /// n = size(xyz, 1); % n: the number of atoms
                /// if nargin == 1
                ///     mass = ones(n,1);
                /// end
                ///
                /// M = sum(mass);
                /// % find the mass center.
                /// m3 = repmat(mass, 1, 3);
                /// center = sum (xyz.*m3)/M;
                /// xyz = xyz - center(ones(n, 1), :);
                ///
                /// mwX = sqrt (m3).*xyz;
                /// inertia = sum(sum(mwX.^2))*eye(3) - mwX'*mwX;
                /// [V,D] = eig(inertia);
                /// tV = V'; % tV: transpose of V. Columns of V are principal axes.
                /// for i=1:3
                ///     trans{i} = tV(ones(n,1)*i, :); % the 3 translations are along principal axes
                /// end
                /// P = zeros(n*3, 6);
                /// for i=1:3
                ///     rotate{i} = cross(trans{i}, xyz);
                ///     temp = mat2vec(trans{i});
                ///     P(:,i) = temp/norm(temp);
                ///     temp = mat2vec(rotate{i});
                ///     P(:,i+3) = temp/norm(temp);
                /// end
                /// m3 = mat2vec(sqrt(m3));
                /// P = repmat (m3(:),1,size(P,2)).*P;
                /// % now normalize columns of P
                /// P = P*diag(1./normMat(P,1));
                ///
                /// function vec = mat2vec(mat)
                /// % convert a matrix to a vector, extracting data *row-wise*.
                /// vec = reshape(mat',1,prod(size(mat)));
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                /// rotx[t_           ] := { { 1,0,0,0},{ 0,Cos[t],-Sin[t],0},{ 0,Sin[t],Cos[t],0},{ 0,0,0,1} };
                /// roty[t_           ] := { { Cos[t],0,Sin[t],0},{ 0,1,0,0},{ -Sin[t],0,Cos[t],0},{ 0,0,0,1} };
                /// rotz[t_           ] := { { Cos[t],-Sin[t],0,0},{ Sin[t],Cos[t],0,0},{ 0,0,1,0},{ 0,0,0,1} };
                /// tran[tx_, ty_, tz_] := { { 1,0,0,tx},{ 0,1,0,ty},{ 0,0,1,tz},{ 0,0,0,1} };
                /// pt                   = Transpose[{{px,py,pz,1}}];
                ///
                /// point  : (px,py,pz)
                /// center : (cx,cy,cz)
                /// angle  : t
                ///
                /// tran[cx, cy, cz].rotx[t].tran[-cx, -cy, -cz].pt           =    {{px}, {cy - cy Cos[t] + py Cos[t] + cz Sin[t] - pz Sin[t]}, {cz - cz Cos[t] + pz Cos[t] - cy Sin[t] + py Sin[t]}, {1}}
                /// tran[cx, cy, cz].roty[t].tran[-cx, -cy, -cz].pt           =    {{cx - cx Cos[t] + px Cos[t] - cz Sin[t] + pz Sin[t]}, {py}, {cz - cz Cos[t] + pz Cos[t] + cx Sin[t] - px Sin[t]}, {1}}
                /// tran[cx, cy, cz].rotz[t].tran[-cx, -cy, -cz].pt           =    {{cx - cx Cos[t] + px Cos[t] + cy Sin[t] - py Sin[t]}, {cy - cy Cos[t] + py Cos[t] - cx Sin[t] + px Sin[t]}, {pz}, {1}}
                ///
                /// D[tran[cx, cy, cz].rotx[t].tran[-cx, -cy, -cz].pt, t]     =    {{0}, {cz Cos[t] - pz Cos[t] + cy Sin[t] - py Sin[t]}, {-cy Cos[t] + py Cos[t] + cz Sin[t] - pz Sin[t]}, {0}}
                /// D[tran[cx, cy, cz].roty[t].tran[-cx, -cy, -cz].pt, t]     =    {{-cz Cos[t] + pz Cos[t] + cx Sin[t] - px Sin[t]}, {0}, {cx Cos[t] - px Cos[t] + cz Sin[t] - pz Sin[t]}, {0}}
                /// D[tran[cx, cy, cz].rotz[t].tran[-cx, -cy, -cz].pt, t]     =    {{cy Cos[t] - py Cos[t] + cx Sin[t] - px Sin[t]}, {-cx Cos[t] + px Cos[t] + cy Sin[t] - py Sin[t]}, {0}, {0}}
                ///
                /// D[tran[cx,cy,cz].rotx[a].tran[-cx,-cy,-cz].pt,a]/.a->0    =    {{0}, {cz - pz}, {-cy + py}, {0}}
                /// D[tran[cx,cy,cz].roty[a].tran[-cx,-cy,-cz].pt,a]/.a->0    =    {{-cz + pz}, {0}, {cx - px}, {0}}
                /// D[tran[cx,cy,cz].rotz[a].tran[-cx,-cy,-cz].pt,a]/.a->0    =    {{cy - py}, {-cx + px}, {0}, {0}}
                ///     rotx of atom (px,py,pz) with center (cx,cy,cz): {{0}, {cz - pz}, {-cy + py}, {0}}    =    { 0, cz - pz, -cy + py, 0 }    =>    {        0,  cz - pz, -cy + py }
                ///     rotx of atom (px,py,pz) with center (cx,cy,cz): {{-cz + pz}, {0}, {cx - px}, {0}}    =    { -cz + pz, 0, cx - px, 0 }    =>    { -cz + pz,        0,  cx - px }
                ///     rotx of atom (px,py,pz) with center (cx,cy,cz): {{cy - py}, {-cx + px}, {0}, {0}}    =    { cy - py, -cx + px, 0, 0 }    =>    {  cy - py, -cx + px,        0 }
                ///

                int leng = coords.Length;

                Vector[] rots;
                {
                    Vector[] rotbyx = new Vector[leng];
                    Vector[] rotbyy = new Vector[leng];
                    Vector[] rotbyz = new Vector[leng];

                    double cx = cent[0];
                    double cy = cent[1];
                    double cz = cent[2];
                    for (int i = 0; i < leng; i++)
                    {
                        double px = coords[i][0];
                        double py = coords[i][1];
                        double pz = coords[i][2];

                        rotbyx[i] = new double[] { 0, cz - pz, -cy + py };
                        rotbyy[i] = new double[] { -cz + pz, 0, cx - px };
                        rotbyz[i] = new double[] { cy - py, -cx + px, 0 };
                    }

                    rots = new Vector[]
                    {
                        rotbyx.ToVector().UnitVector(),
                            rotbyy.ToVector().UnitVector(),
                            rotbyz.ToVector().UnitVector(),
                    };
                }

                if (HDebug.IsDebuggerAttached)
                {
                    Vector[] rotbyx = new Vector[leng];
                    Vector[] rotbyy = new Vector[leng];
                    Vector[] rotbyz = new Vector[leng];

                    Vector zeros = new double[3];
                    for (int i = 0; i < leng; i++)
                    {
                        rotbyx[i] = rotbyy[i] = rotbyz[i] = zeros;
                    }

                    Vector rx = new double[3] {
                        1, 0, 0
                    };
                    Vector ry = new double[3] {
                        0, 1, 0
                    };
                    Vector rz = new double[3] {
                        0, 0, 1
                    };

                    Func <Vector, Vector, Vector> GetTangent = delegate(Vector pt, Vector axisdirect)
                    {
                        /// Magnitude of rotation tangent is proportional to the distance from the point to the axis.
                        /// Ex) when a point is in x-axis (r,0), rotating along z-axis by θ is: (r*sin(θ), 0)
                        ///
                        ///  |
                        ///  |                 ^ sin(θ)
                        ///  |                 |
                        /// -+-----------------r----------
                        ///
                        Vector rot1 = cent;
                        Vector rot2 = cent + axisdirect;
                        double dist = Geometry.DistancePointLine(pt, rot1, rot2);
                        Vector tan  = Geometry.RotateTangentUnit(pt, rot1, rot2) * dist;
                        return(tan);
                    };

                    IEnumerable <int> enumblock = block;
                    if (block != null)
                    {
                        enumblock = block;
                    }
                    else
                    {
                        enumblock = HEnum.HEnumCount(leng);
                    }
                    foreach (int i in enumblock)
                    {
                        Vector pt = coords[i];
                        rotbyx[i] = GetTangent(pt, rx);
                        rotbyy[i] = GetTangent(pt, ry);
                        rotbyz[i] = GetTangent(pt, rz);
                    }

                    Vector[] trots = new Vector[3]
                    {
                        rotbyx.ToVector().UnitVector(),
                             rotbyy.ToVector().UnitVector(),
                             rotbyz.ToVector().UnitVector(),
                    };

                    double test0 = LinAlg.VtV(rots[0], trots[0]);
                    double test1 = LinAlg.VtV(rots[1], trots[1]);
                    double test2 = LinAlg.VtV(rots[2], trots[2]);
                    HDebug.Assert(Math.Abs(test0 - 1) < 0.00000001);
                    HDebug.Assert(Math.Abs(test1 - 1) < 0.00000001);
                    HDebug.Assert(Math.Abs(test2 - 1) < 0.00000001);
                }
                return(rots);
            }
Example #2
0
        /// https://www.charmmtutorial.org/index.php/Full_example

        public static SPsfCrd Solvate
            (IEnumerable <string> toplines
            , IEnumerable <string> parlines
            , IEnumerable <string> psflines_prot
            , IEnumerable <string> crdlines_prot
            , IEnumerable <string> crdlines_water
            )
        {
            string tempbase = @"C:\temp\";

            SPsfCrd psfcrd;

            using (var temp = new HTempDirectory(tempbase, null))
            {
                temp.EnterTemp();
                string topname           = "top.rtf"; HFile.WriteAllLines(topname, toplines);
                string parname           = "par.prm"; HFile.WriteAllLines(parname, parlines);
                string psfname_prot      = "prot.psf"; HFile.WriteAllLines(psfname_prot, psflines_prot);
                string crdname_prot      = "prot.crd"; HFile.WriteAllLines(crdname_prot, crdlines_prot);
                string crdname_water     = "water.crd"; HFile.WriteAllLines(crdname_water, crdlines_water);
                string psfname_protwater = "protwater.psf";
                string crdname_protwater = "protwater.crd";

                string conf_inp = @"* Run Segment Through CHARMM
*

! read topology and parameter files
read rtf  card name $$topname$$
read para card name $$parname$$

! read the psf and coordinate file
read psf  card name $$psfname_prot$$
read coor card name $$crdname_prot$$


! Read in water sequence
read sequence tip3 46656

! Generate new segment for the water
generate bwat noangle nodihedral

! Read the water PDB coordinates and append them to the protein
read coor card append name $$crdname_water$$

! Delete waters which overlap with protein
delete atom sort -
select .byres. (segid bwat .AND. type oh2 .and. -
((.not. (segid bwat .OR. hydrogen)) .around. 2.5)) end

! set headstr = rhdo with a crystal dimension of @greatervalue
set headstr = test xxx

! we want to do a quick-and-dirty minimization to remove bad contacts. Therefore, we should
! set up shake and the non-bond parameters again.
shake bonh param sele all end
nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10.
mini sd nstep 100 nprint 1 tolgrd 100.0

! use Expanded I/O format
ioform extended

! since we've changed the structure by adding waters, we need to write out a new PSF
write psf card name $$psfname_protwater$$
* new_1cbn-18126-1-solv.psf
* solvation: @headstr
*

write coor card name $$crdname_protwater$$
* new_1cbn-18126-1-solv.crd
* solvation: @headstr
*

stop

".Replace("$$topname$$", topname)
                                  .Replace("$$parname$$", parname)
                                  .Replace("$$psfname_prot$$", psfname_prot)
                                  .Replace("$$crdname_prot$$", crdname_prot)
                                  .Replace("$$crdname_water$$", crdname_water)
                                  .Replace("$$psfname_protwater$$", psfname_protwater)
                                  .Replace("$$crdname_protwater$$", crdname_protwater)
                ;
                HFile.WriteAllText("conf.inp", conf_inp);

                System.Console.WriteLine("Run the following command at " + temp + " :");
                System.Console.WriteLine("      $ charmm < conf.inp");
                System.Console.WriteLine("   or $ mpd&");
                System.Console.WriteLine("      $ mpirun -n 38 charmm_M < conf.inp");
                System.Console.WriteLine("Then, copy " + psfname_protwater + " and " + crdname_protwater + " to " + temp);

                while (true)
                {
                    bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true);
                    if (next)
                    {
                        if (HFile.ExistsAll(psfname_protwater, crdname_protwater))
                        {
                            string[] psflines_protwater = HFile.ReadAllLines(psfname_protwater);
                            string[] crdlines_protwater = HFile.ReadAllLines(crdname_protwater);
                            psfcrd = new SPsfCrd
                            {
                                psflines = psflines_protwater,
                                crdlines = crdlines_protwater,
                            };
                            break;
                        }
                        System.Console.WriteLine("DO, copy " + psfname_protwater + " and " + crdname_protwater + " to " + temp);
                    }
                }

                temp.QuitTemp();
            }
            return(psfcrd);
        }
Example #3
0
        /// https://www.charmmtutorial.org/index.php/Full_example

        public static string[] Hessian
            (IEnumerable <string> toplines
            , IEnumerable <string> parlines
            , IEnumerable <string> psflines
            , IEnumerable <string> crdlines
            )
        {
            string tempbase = @"C:\temp\";

            string[] mincrdlines;

            using (var temp = new HTempDirectory(tempbase, null))
            {
                temp.EnterTemp();
                string topname    = "top.rtf"; HFile.WriteAllLines(topname, toplines);
                string parname    = "par.prm"; HFile.WriteAllLines(parname, parlines);
                string psfname    = "target.psf"; HFile.WriteAllLines(psfname, psflines);
                string crdname    = "target.crd"; HFile.WriteAllLines(crdname, crdlines);
                string mincrdname = "target-minimized.crd";

                string conf_inp = @"* Minimize PDB
* Minimize PDB
*

! read topology and parameter file
read rtf   card name top.rtf
read param card name par.prm
! read the psf and coordinate file
read psf  card name target.psf
read coor card name target.crd

! set up shake
shake bonh param sele all end

! set up electrostatics, since we're not using PME, set up switching
! electrostatics
nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10.

energy

coor copy comp


! mini sd nstep 100
! mini abnr nstep 1000 nprint 10000 tolg 0.0000
! ! mini abnr nstep 1000 nprint 100 tolg 0.01
! ! mini abnr nstep 10000000 nprint 100 tolg 0.00
! ! mini abnr nstep   1000000  nprint 100 tolg 10.00    ! target-min-step1-tolg-10_00.crd
! ! mini abnr nstep   1000000  nprint 100 tolg 1.00     ! target-min-step2-tolg-1_00.crd
! ! mini abnr nstep   1000000  nprint 100 tolg 0.10
! ! mini sd nstep 10000                                 ! target-min-step3-sd10000.crd
! ! mini abnr nstep   1000000  nprint 100 tolg 0.01     ! target-min-step4-tolg-0_01.crd
! ! mini abnr nstep   10000  nprint 100 tolg 0.0001     ! target-min-step5-tolg-0_0001.crd
! ! mini abnr nstep   10000  nprint 100 tolg 0.000001   ! target-min-step6-tolg-0_000001.crd
! ! mini abnr nstep   10000  nprint 100 tolg 0.000000     ! target-min-step7-tolg-0_000000.crd
! 
! 
! coor rms
! 
! ioform extended
! 
! write coor card name target-minimized.crd
! * Initial minimization, no PME.
! *

! VIBRAN NMOD 20 ATOM FSWITCH rdie eps 4.0 VDW VSHIFT cutnb 13.0 ctofnb 12.0 CTONNB 8.0
! 
! DIMB ITERations 500 TOLErance 0.04 PARDim 200 IUNMode 21 DWIN
! 
! WRITe SECOnd-derivatives card

! BOMLEV -2
! VIBRAN
! DIAG ENTRopy

! VIBRan NMODes 500
! DIAG
! print norm vector dipole

!mini abnr nstep   100  nprint 100 tolg 0.000000     ! target-min-step7-tolg-0_000000.crd
BOMLEV -2
open unit 1 write form name " + " \"second.dat\" " + @" 
REDUce CMPAct
vibran
!diag
write second card unit 1
close unit 1

!calc natom3 ?NATOM *3
!vibran nmode @natom3
!diag
!print norm

!bomlev - 2
!VIBRan NMOD 300
!DIAGonalize


!https://www.charmm.org/charmm/documentation/by-version/c42b1/params/doc/vibran/

stop



";
                conf_inp = conf_inp.Replace("$$topname$$", topname)
                           .Replace("$$parname$$", parname)
                           .Replace("$$psfname$$", psfname)
                           .Replace("$$crdname$$", crdname)
                           .Replace("$$mincrdname$$", mincrdname)
                ;
                HFile.WriteAllText("conf.inp", conf_inp);

                System.Console.WriteLine("Run the following command at " + temp + " :");
                System.Console.WriteLine("      $ charmm < conf.inp");
                System.Console.WriteLine("   or $ mpd&");
                System.Console.WriteLine("      $ mpirun -n 38 charmm_M < conf.inp");
                System.Console.WriteLine("Then, copy second.dat to " + temp);

                while (true)
                {
                    bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true);
                    if (next)
                    {
                        if (HFile.ExistsAll(mincrdname))
                        {
                            mincrdlines = HFile.ReadAllLines(mincrdname);
                            /// second.dat has the following format
                            ///
                            /// num-atoms
                            /// pot-energy
                            /// atom1-xforce  atom1-yforce atom1-zforce
                            /// atom2-xforce  atom2-yforce atom2-zforce
                            ///         ...
                            /// atomn-xforce  atomn-yforce atomn-zforce
                            /// upper- or lower-diag elem 1
                            /// upper- or lower-diag elem 2
                            ///   ....
                            /// upper- or lower-diag elem 3n*3n/2
                            /// atom1-xcoord  atom1-ycoord atom1-zcoord
                            /// atom2-xcoord  atom2-ycoord atom2-zcoord
                            ///         ...
                            /// atomn-xcoord  atomn-ycoord atomn-zcoord
                            ///
                            break;
                        }
                        System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp);
                    }
                }

                temp.QuitTemp();
            }
            return(mincrdlines);
        }
Example #4
0
            public static ONewton Newton(string tinkerpath
                                         , Tinker.Xyz xyz
                                         , Tinker.Xyz.Atom.Format xyz_atoms_format
                                         , Tinker.Prm prm
                                         , string tempbase
                                         , string copytemp                    // = null
                                         , string param
                                                                              //, string precondition               // = "A"  // Precondition via Auto/None/Diag/Block/SSOR/ICCG [A] :  A
                                                                              //, double gradCriterion              // = 0.01 // Enter RMS Gradient per Atom Criterion [0.01] : 0.001
                                         , IList <Tinker.Xyz.Atom> atomsToFix // = null
                                         , bool pause                         // = false
                                         , params string[] keys
                                         )
            {
                if (HDebug.IsDebuggerAttached && atomsToFix != null)
                {
                    Dictionary <int, Tinker.Xyz.Atom> xyzatoms = xyz.atoms.ToIdDictionary();
                    foreach (var atom in atomsToFix)
                    {
                        HDebug.Assert(object.ReferenceEquals(atom, xyzatoms[atom.Id]));
                    }
                }
                Tinker.Xyz minxyz;
                string[]   minlog;
                using (var temp = new HTempDirectory(tempbase, copytemp))
                {
                    temp.EnterTemp();

                    if (tinkerpath == null)
                    {
                        string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.tinker_6_2_06.";
                        HResource.CopyResourceTo <Tinker>(resbase + "newton.exe", "newton.exe");
                        tinkerpath = "newton.exe";
                    }
                    xyz.ToFile("prot.xyz", false);
                    prm.ToFile("prot.prm");
                    List <string> keylines = new List <string>(keys);
                    if (atomsToFix != null)
                    {
                        foreach (var atom in atomsToFix)
                        {
                            Vector coord          = atom.Coord;
                            double force_constant = 10000; // force constant in kcal/Å2 for the harmonic restraint potential
                            string keyline        = string.Format("RESTRAIN-POSITION     {0}  {1}  {2}  {3}  {4}", atom.Id, coord[0], coord[1], coord[2], force_constant);
                            keylines.Add(keyline);
                        }
                    }
                    HFile.WriteAllLines("prot.key", keylines);
                    // Precondition via Auto/None/Diag/Block/SSOR/ICCG [A] :  A
                    // Enter RMS Gradient per Atom Criterion [0.01] : 0.001
                    //bool pause = false;
                    string command = tinkerpath;
                    command += string.Format("  prot.xyz  prot.prm");
                    command += string.Format("  -k  prot.key");
                    command += string.Format("  {0}", param);
                    HProcess.StartAsBatchInConsole("newton.bat", pause
                                                   , "time /t  >> prot.log"
                                                   , command //+" >> prot.log"
                                                   , "time /t  >> prot.log"
                                                   );
                    HDebug.Assert(HFile.Exists("prot.xyz_2"));
                    HDebug.Assert(HFile.Exists("prot.xyz_3") == false);
                    minxyz = Tinker.Xyz.FromFile("prot.xyz_2", false, xyz_atoms_format);
                    minlog = HFile.ReadAllLines("prot.log");
                    temp.QuitTemp();
                }

                return(new ONewton
                {
                    minxyz = minxyz,
                    minlog = minlog
                });
            }
Example #5
0
        /// https://www.charmmtutorial.org/index.php/Full_example

        public static string[] MinimizeCrd
            (IEnumerable <string> toplines
            , IEnumerable <string> parlines
            , IEnumerable <string> psflines
            , IEnumerable <string> crdlines
            , string conf_inp_mini
            )
        {
            string tempbase = @"C:\temp\";

            if (conf_inp_mini == null)
            {
                conf_inp_mini = @"
mini sd nstep 100
mini abnr nstep 1000 nprint 10000 tolg 0.0001
! mini abnr nstep 1000 nprint 100 tolg 0.01
! mini abnr nstep 10000000 nprint 100 tolg 0.00
! mini abnr nstep   1000000  nprint 100 tolg 10.00    ! target-min-step1-tolg-10_00.crd
! mini abnr nstep   1000000  nprint 100 tolg 1.00     ! target-min-step2-tolg-1_00.crd
! mini abnr nstep   1000000  nprint 100 tolg 0.10
! mini sd nstep 10000                                 ! target-min-step3-sd10000.crd
! mini abnr nstep   1000000  nprint 100 tolg 0.01     ! target-min-step4-tolg-0_01.crd
! mini abnr nstep   10000  nprint 100 tolg 0.0001     ! target-min-step5-tolg-0_0001.crd
! mini abnr nstep   10000  nprint 100 tolg 0.000001   ! target-min-step6-tolg-0_000001.crd
! mini abnr nstep   10000  nprint 100 tolg 0.000000     ! target-min-step7-tolg-0_000000.crd
";
            }

            string[] mincrdlines;

            using (var temp = new HTempDirectory(tempbase, null))
            {
                temp.EnterTemp();
                string topname    = "top.rtf"; HFile.WriteAllLines(topname, toplines);
                string parname    = "par.prm"; HFile.WriteAllLines(parname, parlines);
                string psfname    = "target.psf"; HFile.WriteAllLines(psfname, psflines);
                string crdname    = "target.crd"; HFile.WriteAllLines(crdname, crdlines);
                string mincrdname = "target-minimized.crd";

                string conf_inp = @"* Minimize PDB
*

! read topology and parameter file
read rtf   card name $$topname$$
read param card name $$parname$$
! read the psf and coordinate file
read psf  card name $$psfname$$
read coor card name $$crdname$$

! set up shake
shake bonh param sele all end

! set up electrostatics, since we're not using PME, set up switching
! electrostatics
nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10.

energy

coor copy comp

" + conf_inp_mini + @"

coor rms

ioform extended

write coor card name $$mincrdname$$
* Initial minimization, no PME.
*

stop


";
                conf_inp = conf_inp.Replace("$$topname$$", topname)
                           .Replace("$$parname$$", parname)
                           .Replace("$$psfname$$", psfname)
                           .Replace("$$crdname$$", crdname)
                           .Replace("$$mincrdname$$", mincrdname)
                ;
                HFile.WriteAllText("conf.inp", conf_inp);

                System.Console.WriteLine("Run the following command at " + temp + " :");
                System.Console.WriteLine("      $ charmm < conf.inp");
                System.Console.WriteLine("   or $ mpd&");
                System.Console.WriteLine("      $ mpirun -n 38 charmm_M < conf.inp");
                System.Console.WriteLine("Then, copy target-minimized.crd to " + temp);

                while (true)
                {
                    bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true);
                    if (next)
                    {
                        if (HFile.ExistsAll(mincrdname))
                        {
                            mincrdlines = HFile.ReadAllLines(mincrdname);
                            break;
                        }
                        System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp);
                    }
                }

                temp.QuitTemp();
            }
            return(mincrdlines);
        }
Example #6
0
            public static OMinimize Minimize(string minimizepath
                                             , Tinker.Xyz xyz
                                             , Tinker.Xyz.Atom.Format xyz_atoms_format
                                             , Tinker.Prm prm
                                             , string tempbase
                                             , string copytemp                    // = null
                                             , string param
                                             , IList <Tinker.Xyz.Atom> atomsToFix // = null
                                             , bool pause                         // = false
                                             , params string[] keys
                                             )
            {
                if (HDebug.IsDebuggerAttached && atomsToFix != null)
                {
                    Dictionary <int, Tinker.Xyz.Atom> xyzatoms = xyz.atoms.ToIdDictionary();
                    foreach (var atom in atomsToFix)
                    {
                        HDebug.Assert(object.ReferenceEquals(atom, xyzatoms[atom.Id]));
                    }
                }
                Tinker.Xyz minxyz;
                string[]   minlog;
                using (var temp = new HTempDirectory(tempbase, copytemp))
                {
                    temp.EnterTemp();
                    xyz.ToFile("prot.xyz", false);
                    prm.ToFile("prot.prm");
                    List <string> keylines = new List <string>();
                    //if(grdmin != null)
                    //{
                    //    string keyline = string.Format("GRDMIN                {0}", grdmin.Value);
                    //    keylines.Add(keyline);
                    //}
                    if (atomsToFix != null)
                    {
                        foreach (var atom in atomsToFix)
                        {
                            Vector coord          = atom.Coord;
                            double force_constant = 10000; // force constant in kcal/Å2 for the harmonic restraint potential
                            string keyline        = string.Format("RESTRAIN-POSITION     {0}  {1}  {2}  {3}  {4}", atom.Id, coord[0], coord[1], coord[2], force_constant);
                            keylines.Add(keyline);
                        }
                    }
                    if (keys != null)
                    {
                        keylines.AddRange(keys);
                    }
                    HFile.WriteAllLines("prot.key", keylines);
                    // Enter RMS Gradient per Atom Criterion [0.01] :
                    string command = minimizepath;
                    command += "  prot.xyz  prot.prm";
                    command += "  -k  prot.key  <  param.txt";

                    HFile.WriteAllLines("param.txt", param.HSplit());

                    //command += string.Format("  >> prot.log");
                    HProcess.StartAsBatchInConsole("minimize.bat", pause
                                                   , "time /t >> prot.log"
                                                   , command
                                                   , "time /t >> prot.log"
                                                   );
                    HDebug.Assert(HFile.Exists("prot.xyz_2"));
                    HDebug.Assert(HFile.Exists("prot.xyz_3") == false);
                    minxyz = Tinker.Xyz.FromFile("prot.xyz_2", false, xyz.atoms_format);
                    minlog = HFile.ReadAllLines("prot.log");
                    temp.QuitTemp();
                }

                return(new OMinimize
                {
                    minxyz = minxyz,
                    minlog = minlog
                });
            }
Example #7
0
            public static void SelfTest(string pdbname, string psfname, string prmname, string xyzname)
            {
                using (var temp = new HTempDirectory(@"C:\temp\", null))
                {
                    temp.EnterTemp();
                    {
                        string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.selftest.";
                        HResource.CopyResourceTo <Tinker>(resbase + pdbname, pdbname);
                        HResource.CopyResourceTo <Tinker>(resbase + psfname, psfname);
                        HResource.CopyResourceTo <Tinker>(resbase + "par_all27_prot_lipid.inp", prmname);
                        if (xyzname != null)
                        {
                            HResource.CopyResourceTo <Tinker>(resbase + xyzname, xyzname);
                        }
                        HResource.CopyResourceTo <Tinker>(resbase + "charmm22.prm", "charmm22.prm");

                        {
                            var pdb = Pdb.FromFile(pdbname);
                            var psf = Namd.Psf.FromFile(psfname);
                            var prm = Namd.Prm.FromFile(prmname);

                            var xyz_prm = BuildFromNamd(pdb, psf, prm);
                            xyz_prm.Item1.ToFile("TinkFromNamd.xyz", false);
                            xyz_prm.Item2.ToFile("TinkFromNamd.prm");
                        }

                        if (xyzname != null)
                        {
                            var xyz0  = Xyz.FromFile("TinkFromNamd.xyz", false);
                            var prm0  = Prm.FromFile("TinkFromNamd.prm");
                            var grad0 = Run.Testgrad(xyz0, prm0, @"C:\temp\"
                                                     //, "VDWTERM     NONE"
                                                     //, "CHARGETERM  NONE"
                                                     //, "BONDTERM    NONE"
                                                     //, "ANGLETERM   NONE"
                                                     //, "UREYTERM    NONE"
                                                     //, "IMPROPTERM  NONE"
                                                     //, "TORSIONTERM NONE"
                                                     );
                            var forc0 = grad0.anlyts.GetForces(xyz0.atoms);

                            var xyz1  = Xyz.FromFile(xyzname, false);
                            var prm1  = Prm.FromFile("charmm22.prm");
                            var grad1 = Run.Testgrad(xyz1, prm1, @"C:\temp\"
                                                     //, "VDWTERM     NONE"
                                                     //, "CHARGETERM  NONE"
                                                     //, "BONDTERM    NONE"
                                                     //, "ANGLETERM   NONE"
                                                     //, "UREYTERM    NONE"
                                                     //, "IMPROPTERM  NONE"
                                                     //, "TORSIONTERM NONE"
                                                     );
                            var forc1 = grad1.anlyts.GetForces(xyz1.atoms);
                            {
                                KDTree.KDTree <object> kdtree = new KDTree.KDTree <object>(3);
                                var atoms0 = xyz0.atoms;
                                for (int i = 0; i < atoms0.Length; i++)
                                {
                                    kdtree.insert(atoms0[i].Coord, i);
                                }
                                var   atoms1  = xyz1.atoms;
                                int[] idx1to0 = new int[atoms1.Length];
                                for (int i1 = 0; i1 < atoms1.Length; i1++)
                                {
                                    Vector coord1 = atoms1[i1].Coord;
                                    int    i0     = (int)kdtree.nearest(coord1);
                                    Vector coord0 = atoms0[i0].Coord;
                                    kdtree.delete(coord0);
                                    idx1to0[i0] = i1;
                                }
                                atoms1 = atoms1.HSelectByIndex(idx1to0);
                                forc1  = forc1.HSelectByIndex(idx1to0);
                            }

                            Vector[] dforc     = VectorBlock.PwSub(forc0, forc1).ToArray();
                            double[] dforcl    = dforc.Dist();
                            double   max_dforc = dforc.Dist().Max();
                            HDebug.Exception(max_dforc < 1);       // 0.72682794387667848

                            {
                                double EB   = Math.Abs(grad0.enrgCmpnt.EB - grad1.enrgCmpnt.EB);    HDebug.Exception(EB < 0.1);
                                double EA   = Math.Abs(grad0.enrgCmpnt.EA - grad1.enrgCmpnt.EA);    HDebug.Exception(EA < 0.1);
                                double EBA  = Math.Abs(grad0.enrgCmpnt.EBA - grad1.enrgCmpnt.EBA);    HDebug.Exception(EBA < 0.1);
                                double EUB  = Math.Abs(grad0.enrgCmpnt.EUB - grad1.enrgCmpnt.EUB);    HDebug.Exception(EUB < 0.1);
                                double EAA  = Math.Abs(grad0.enrgCmpnt.EAA - grad1.enrgCmpnt.EAA);    HDebug.Exception(EAA < 0.1);
                                double EOPB = Math.Abs(grad0.enrgCmpnt.EOPB - grad1.enrgCmpnt.EOPB);    HDebug.Exception(EOPB < 0.1);
                                double EOPD = Math.Abs(grad0.enrgCmpnt.EOPD - grad1.enrgCmpnt.EOPD);    HDebug.Exception(EOPD < 0.1);
                                double EID  = Math.Abs(grad0.enrgCmpnt.EID - grad1.enrgCmpnt.EID);    HDebug.Exception(EID < 0.1);          // 0.0019000000000000128 : N-terminus (and C-terminus) information is/are inconsistent betweeen namd-charmm and tink-charmm22
                                double EIT  = Math.Abs(grad0.enrgCmpnt.EIT - grad1.enrgCmpnt.EIT);    HDebug.Exception(EIT < 0.1);
                                double ET   = Math.Abs(grad0.enrgCmpnt.ET - grad1.enrgCmpnt.ET);    HDebug.Exception(ET < 0.5);             // 0.33029999999999404   : N-terminus (and C-terminus) information is/are inconsistent betweeen namd-charmm and tink-charmm22
                                double EPT  = Math.Abs(grad0.enrgCmpnt.EPT - grad1.enrgCmpnt.EPT);    HDebug.Exception(EPT < 0.1);
                                double EBT  = Math.Abs(grad0.enrgCmpnt.EBT - grad1.enrgCmpnt.EBT);    HDebug.Exception(EBT < 0.1);
                                double ETT  = Math.Abs(grad0.enrgCmpnt.ETT - grad1.enrgCmpnt.ETT);    HDebug.Exception(ETT < 0.1);
                                double EV   = Math.Abs(grad0.enrgCmpnt.EV - grad1.enrgCmpnt.EV);    HDebug.Exception(EV < 0.1);
                                double EC   = Math.Abs(grad0.enrgCmpnt.EC - grad1.enrgCmpnt.EC);    HDebug.Exception(EC < 0.5);             // 0.37830000000002428
                                double ECD  = Math.Abs(grad0.enrgCmpnt.ECD - grad1.enrgCmpnt.ECD);    HDebug.Exception(ECD < 0.1);
                                double ED   = Math.Abs(grad0.enrgCmpnt.ED - grad1.enrgCmpnt.ED);    HDebug.Exception(ED < 0.1);
                                double EM   = Math.Abs(grad0.enrgCmpnt.EM - grad1.enrgCmpnt.EM);    HDebug.Exception(EM < 0.1);
                                double EP   = Math.Abs(grad0.enrgCmpnt.EP - grad1.enrgCmpnt.EP);    HDebug.Exception(EP < 0.1);
                                double ER   = Math.Abs(grad0.enrgCmpnt.ER - grad1.enrgCmpnt.ER);    HDebug.Exception(ER < 0.1);
                                double ES   = Math.Abs(grad0.enrgCmpnt.ES - grad1.enrgCmpnt.ES);    HDebug.Exception(ES < 0.1);
                                double ELF  = Math.Abs(grad0.enrgCmpnt.ELF - grad1.enrgCmpnt.ELF);    HDebug.Exception(ELF < 0.1);
                                double EG   = Math.Abs(grad0.enrgCmpnt.EG - grad1.enrgCmpnt.EG);    HDebug.Exception(EG < 0.1);
                                double EX   = Math.Abs(grad0.enrgCmpnt.EX - grad1.enrgCmpnt.EX);    HDebug.Exception(EX < 0.1);
                            }
                        }
                    }
                    temp.QuitTemp();
                }

                //{
                //    //string pathbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\1A6G\New folder\";
                //    string pathbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\1A6G\";
                //    string toplbase = @"C:\Users\htna.IASTATE\svn\htnasvn_htna\Research.bioinfo.prog.NAMD\top_all27_prot_lipid\";
                //    var pdb = Pdb     .FromFile(pathbase+"1A6G.psfgen.pdb");
                //    var psf = Namd.Psf.FromFile(pathbase+"1A6G.psfgen.psf");
                //    var prm = Namd.Prm.FromFile(toplbase+"par_all27_prot_na.prm");
                //
                //        pdb = Pdb     .FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\1M6J.psfgen.pdb");
                //        psf = Namd.Psf.FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\1M6J.psfgen.psf");
                //        prm = Namd.Prm.FromFile(@"K:\Tim-8TIM,1TPH,1M6J\Tim-1M6J\par_all27_prot_lipid.inp");
                //    var xyz_prm = BuildFromNamd(pdb, psf, prm);
                //    xyz_prm.Item1.ToFile(@"C:\temp\TinkFromNamd.xyz", false);
                //    xyz_prm.Item2.ToFile(@"C:\temp\TinkFromNamd.prm");
                //}
            }
Example #8
0
        public static SPsfCrd BuildPsfCrd
            (IEnumerable <string> toplines
            , IEnumerable <string> parlines
            , IEnumerable <string> pdblines
            )
        {
            string tempbase = @"C:\temp\";

            SPsfCrd psfcrd;

            using (var temp = new HTempDirectory(tempbase, null))
            {
                temp.EnterTemp();
                string topname = "top.rtf"; HFile.WriteAllLines(topname, toplines);
                string parname = "par.prm"; HFile.WriteAllLines(parname, parlines);

                string tgtname = "target"; HFile.WriteAllLines(tgtname + ".pdb", pdblines);

                string Setup_inp = @"* Run Segment Through CHARMM
*

! read topology and parameter files

read rtf  card name $$topname$$
read para card name $$parname$$

! Read sequence from the PDB coordinate file
open unit 1 card read name $$tgtname$$.pdb
read sequ pdb unit 1

! now generate the PSF and also the IC table (SETU keyword)
generate setu a-pro first NTER last CTER

rewind unit 1

! set bomlev to -1 to avois sying on lack of hydrogen coordinates
bomlev -1
read coor pdb unit 1
! them put bomlev back up to 0
bomlev 0

close unit 1

! prints out number of atoms that still have undefined coordinates.
define test select segid a-pro .and. ( .not. hydrogen ) .and. ( .not. init ) show end

ic para
ic fill preserve
ic build
hbuild sele all end

! write out the protein structure file (psf) and
! the coordinate file in pdb and crd format.

write psf card name $$tgtname$$.psf
* PSF
*

write coor card name $$tgtname$$.crd
* Coords
*

stop

"
                                   .Replace("$$topname$$", topname)
                                   .Replace("$$parname$$", parname)
                                   .Replace("$$tgtname$$", tgtname);
                HFile.WriteAllText("Setup.inp", Setup_inp);

                System.Console.WriteLine("Run the following command at " + temp + " :");
                System.Console.WriteLine("      $ charmm < Setup.inp");
                System.Console.WriteLine("   or $ mpd&");
                System.Console.WriteLine("      $ mpirun -n 38 charmm_M < Setup.inp");
                System.Console.WriteLine("Then, copy target.psf and target.crd to " + temp);

                while (true)
                {
                    bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true);
                    if (next)
                    {
                        if (HFile.ExistsAll("target.crd", "target.psf"))
                        {
                            string[] crdlines = HFile.ReadAllLines("target.crd");
                            string[] psflines = HFile.ReadAllLines("target.psf");
                            psfcrd = new SPsfCrd
                            {
                                crdlines = crdlines,
                                psflines = psflines,
                            };
                            break;
                        }
                        System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp);
                    }
                }

                temp.QuitTemp();
            }

            return(psfcrd);
        }
Example #9
0
        public static CPsfgenExt PsfgenExt
            (IList <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms
            , string[] toplines
            , string[] parlines
            , Pdb alignto
            , string[] psfgen_lines
            , IList <string> minimize_conf_lines = null
            , HOptions options = null
            )
        {
            if (options == null)
            {
                options = new HOptions((string)null);
            }
            string tempbase       = @"C:\temp\";
            string psfgen_workdir = null;
            string topname        = "prot.top";
            string parname        = "prot.par";

            List <string> psf_lines = null;
            List <string> pdb_lines = null;

            using (var temp = new HTempDirectory(tempbase, null))
            {
                temp.EnterTemp();

                HFile.WriteAllLines(topname, toplines);
                HFile.WriteAllLines(parname, parlines);

                if ((HFile.Exists("prot.pdb") == false) || (HFile.Exists("prot.psf") == false))
                {
                    var psfgen = Namd.RunPsfgen
                                     (lstSegFileAtoms, tempbase, null, "2.10"
                                     , new string[] { topname }
                                     , new string[] {}
                                     , topname
                                     , psfgen_lines: psfgen_lines
                                     , psfgen_workdir: psfgen_workdir
                                     , options: options
                                     );

                    psf_lines = psfgen.psf_lines;
                    pdb_lines = psfgen.pdb_lines;
                    if (alignto != null)
                    {
                        HDebug.Exception("check!!!");
                        ////////////////////////////
                        Pdb prot = Pdb.FromLines(pdb_lines);
                        prot      = PsfgenExt_AlignTo(prot, alignto);
                        pdb_lines = prot.ToLines().ToList();
                    }
                    HFile.WriteAllLines("prot.pdb", pdb_lines);
                    HFile.WriteAllLines("prot.psf", psf_lines);
                }

                if (options.Contains("nomin") == false)
                {
                    if ((HFile.Exists("protmin.coor") == false) || (HFile.Exists("protmin.pdb") == false))
                    {
                        List <string> psfgen_pdb_lines = System.IO.File.ReadLines("prot.pdb").ToList();
                        List <string> psfgen_psf_lines = System.IO.File.ReadLines("prot.psf").ToList();

                        List <string> prm_lines = System.IO.File.ReadLines(parname).ToList();
                        string        Namd2_opt = null;
                        if (options.HSelectStartsWith("minimize option:").Length >= 1)
                        {
                            Namd2_opt = options.HSelectStartsWith("minimize option:").First().Replace("minimize option:", "");
                        }
                        var minpdb = Namd.Run.Namd2
                                         (psfgen_pdb_lines
                                         , psfgen_psf_lines
                                         , prm_lines
                                         , tempbase
                                         , "2.10"
                                         , ((Namd2_opt == null) ? "+p3" : Namd2_opt)
                                         , conf_lines: minimize_conf_lines
                                         );
                        HFile.WriteAllLines("protmin.coor", minpdb.coor_lines);

                        Pdb prot0 = Pdb.FromLines(psfgen_pdb_lines);
                        Pdb prot1 = Pdb.FromLines(minpdb.coor_lines);
                        HDebug.Exception(prot0.atoms.Length == prot1.atoms.Length);
                        HDebug.Exception(prot0.elements.Length == prot1.elements.Length);
                        // update conformation to minimized conformation
                        for (int i = 0; i < prot0.elements.Length; i++)
                        {
                            if (prot0.elements[i].GetType() != prot1.elements[i].GetType())
                            {
                                throw new HException("prot0.elements[i].GetType() != prot1.elements[i].GetType()");
                            }
                            if ((prot0.elements[i] is Pdb.IAtom) == false)
                            {
                                continue;
                            }
                            Pdb.IAtom iatom0 = prot0.elements[i] as Pdb.IAtom;
                            Pdb.IAtom iatom1 = prot1.elements[i] as Pdb.IAtom;
                            Vector    coord0 = iatom0.coord;
                            Vector    coord1 = iatom1.coord;
                            double    dist   = (coord0 - coord1).Dist;
                            if (iatom0.occupancy != 0)
                            {
                                if (dist != 0)
                                {
                                    throw new HException("iatom0.coord - iatom1.coord != 0");
                                }
                            }
                            if (dist != 0)
                            {
                                if (iatom0 is Pdb.Atom)
                                {
                                    string   nline0 = (iatom0 as Pdb.Atom).GetUpdatedLine(coord1);
                                    Pdb.Atom natom0 = Pdb.Atom.FromString(nline0);
                                    prot0.elements[i] = natom0;
                                    continue;
                                }
                                if (iatom0 is Pdb.Hetatm)
                                {
                                    string     nline0 = (iatom0 as Pdb.Hetatm).GetUpdatedLine(coord1);
                                    Pdb.Hetatm natom0 = Pdb.Hetatm.FromString(nline0);
                                    prot0.elements[i] = natom0;
                                    continue;
                                }
                            }
                        }
                        if ((prot0.elements[0] is Pdb.Remark) && (prot1.elements[0] is Pdb.Remark))
                        {
                            prot0.elements[0] = Pdb.Remark.FromString(prot1.elements[0].line);
                        }
                        prot0.ToFile("protmin.pdb");
                        pdb_lines = System.IO.File.ReadLines("protmin.pdb").ToList();
                    }
                }

                //{
                //    Pdb confpdb = GetConfPdb(options);
                //    var psf    = Namd.Psf.FromFile("prot.psf");
                //    var prm    = Namd.Prm.FromFile(parname);
                //    List<string> log = new List<string>();
                //    Universe  univ = Universe.BuilderNamd.Build(psf, prm, confpdb, true, new TextLogger(log));
                //    return univ;
                //}
                temp.QuitTemp();
            }

            return(new CPsfgenExt
            {
                psflines = psf_lines,
                pdblines = pdb_lines,
            });
        }