~sfiorucci/ptools/test_seb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "surface.h"
#include "attractrigidbody.h"

#include <cassert>

namespace PTools
{

void Surface::setUp(int nphi, int ncosth)
{
    // dimension csth(ncosth),snth(ncosth),phgh(nphi)

    const dbl pi= 3.141592654;
    //  precalculate costh,sinth and phigh for different ncosth...
    for (uint ik=0; ik < (uint) ncosth; ik++)
    {
        csth.push_back (   -1.0 + ( ( (dbl) ik+1) - 0.5  ) * (2.0 / (dbl) ncosth ) ) ;
        snth.push_back (   sqrt(1.0 -csth[ik]*csth[ik] ) );
    }

    for ( int ik=0; ik<nphi; ik++)
    {
        cos_phgh.push_back ( cos(2.0 * pi *  ((dbl)ik-1.0)/(dbl) nphi )) ;
        sin_phgh.push_back ( sin(2.0 * pi *  ((dbl)ik-1.0)/(dbl) nphi )) ;
    }

}

void Surface::surfpointParams(int max, dbl shift)
{
    m_numneh = max;
    m_sradshift = shift;
    m_init=true;
}

void Surface::readsolvparam(const std::string& file)
{
    std::string line ;
    //int count = 0;
    radi.clear();

    std::ifstream sfile(file.c_str());
    if (! sfile)
        {
            //  the file cannot be opened
            std::string msg = " Cannot Locate file ";
	    msg.append(file.c_str());
	    msg.append("\n");
            std::cerr << msg ;
            throw msg;
	}

    while (std::getline(sfile, line))
    {
        //count++ ; // count number of line (unused at the moment)
        //int size_line = line.size(); // count line length (unused at the moment)
        //dbl data1=atof(line.substr(1,6).c_str()); // read first column - atom type id (unused at the moment)
        dbl data2=atof(line.substr(7,13).c_str()); // read second column - radius (unused at the moment)
        //dbl data3=atof(line.substr(14,20).c_str()); // read third column - solvation parameters (unused at the moment)
        //std::string data4=line.substr(21,size_line).c_str(); // read last column (unused at the moment)
        radi.push_back(data2);
     }
}

Rigidbody Surface::surfpoint(const Rigidbody & rigid, dbl srad)
{
    Rigidbody rigidsurf;
    int size_rigid = rigid.Size();
    std::vector<int> neigh;
    radius.clear();

    // fix neighbours parameters if not initialized
    if (!m_init)
    {
        m_numneh = 2000;
        m_sradshift = 0.0;
    }
    // read radius
    AttractRigidbody rigid_tmp(rigid);
    m_atomtypenumber.resize(size_rigid);
    for (uint i=0; i< rigid_tmp.Size(); i++)
    { m_atomtypenumber[i] = rigid_tmp.getAtomTypeNumber(i);}
    for (int i=0; i<size_rigid; i++)
    {
        Atom m_atom = rigid_tmp.CopyAtom(i);
        radius.push_back(radi[m_atomtypenumber[i]]);
    }

    // generate grid points
    for (int i=0; i<size_rigid; i++)
        if ( radius[i] != 0.0 )
        {
            Coord3D coord1 = rigid.GetCoords(i);
            int numneh = 0;
            neigh.clear();
            for (int j=0; j<size_rigid; j++) // generate neighbor list
                if (i!=j)
                {
                    Coord3D coord2 = rigid.GetCoords(j);
                    dbl ccdist = Norm2(coord1 - coord2);
                    dbl rr = (radius[i]+radius[j]+2.0*srad) * (radius[i]+radius[j]+2.0*srad);
                    if (ccdist <= rr)
                    { neigh.push_back(j);
                        numneh+=1;
                        if  ( numneh > m_numneh )
                        {
                            std::string msg = " ERROR: Atom has too many neighbors \n"  ;
                            std::cout << msg;
                            throw msg;
                        }
                    }
                }
            numneh = numneh - 1;
            for (int j=0; j<m_ncosth; j++) // generate points around each atoms
            {
                dbl costh = csth[j];
                dbl sinth = snth[j];
                for (int k=0; k<m_nphi; k++)
                {
                    dbl cphigh = cos_phgh[k];
                    dbl sphigh = sin_phgh[k];
                    Coord3D coord4;
                    coord4.x = (radius[i]+srad+m_sradshift)*sinth*cphigh;
                    coord4.y = (radius[i]+srad+m_sradshift)*sinth*sphigh;
                    coord4.z = (radius[i]+srad+m_sradshift)*costh;
                    int l = 0;
                    bool coverd = false;
                    while ((!coverd) && (l <= numneh))
                    {
                        Coord3D coord5 = rigid.GetCoords(neigh[l]);
                        dbl ddd = Norm2(coord1 + coord4 - coord5);
                        if (ddd < (radius[neigh[l]] + srad+m_sradshift)*(radius[neigh[l]] + srad+m_sradshift))
                        { coverd = true; }
                        l+=1;
                    }
                    if (!coverd)
                    {
                        Atom m_atom2 = rigid.CopyAtom(i);
                        m_atom2.SetCoords(coord1 + coord4);
                        rigidsurf.AddAtom(m_atom2);
                    }
                }
            }

            // fill the top and bottom positions
            dbl costh = -1;
            while (costh<=1.0)
            {
                Coord3D coord4;
                coord4.x = 0.0;
                coord4.y = 0.0;
                coord4.z = (radius[i]+srad+m_sradshift)*costh;
                int l = 0;
                bool coverd = false;
                while ((!coverd) && (l <= numneh))
                {
                    Coord3D coord5 = rigid.GetCoords(neigh[l]);
                    dbl ddd = Norm2(coord1 + coord4 - coord5);
                    if (ddd < (radius[neigh[l]] + srad+m_sradshift)*(radius[neigh[l]] + srad+m_sradshift))
                    { coverd = true; }
                    l+=1;
                }
                if (!coverd)
                {
                    Atom m_atom2 = rigid.CopyAtom(i);
                    m_atom2.SetCoords(coord1 + coord4);
                    rigidsurf.AddAtom(m_atom2);
                }
                costh+=2;
            }
        }
    return rigidsurf;
}

Rigidbody Surface::outergrid(const Rigidbody & rigid1, const Rigidbody & rigid2, dbl srad)
{
    int size1 = rigid1.Size();
    int size2 = rigid2.Size();
    Rigidbody rigid3;
    for (int i=0; i<size1; i++)
    {
        Coord3D xyz1 = rigid1.GetCoords(i);
        bool select = true;
        for (int j=0; j<size2; j++)
        {
            Coord3D xyz2 = rigid2.GetCoords(j);
            dbl dist=Norm2(xyz1-xyz2);
            if (dist < srad) { select = false; }
        }
        if (select) { rigid3.AddAtom(rigid1.CopyAtom(i)); }
    }
    return rigid3;
}

Rigidbody Surface::removeclosest(const Rigidbody & rigid, dbl srad)
{
    std::vector<bool> list,list2;
    int size=rigid.Size();
    Rigidbody rigid2;
    list.clear();
    srad=srad*srad;
    for (int i=0; i<size; i++) { list.push_back(true); }
    for (int i=0; i<size; i++)
    {
        Coord3D  xyz1 = rigid.GetCoords(i);
        for (int j=0; j<size; j++)
            if ((list[i]) && (i!=j))
            {
                Coord3D  xyz2 = rigid.GetCoords(j);
                dbl dist=Norm2(xyz1 - xyz2);
                if (dist < srad) { list[j] = false; }
            }
    }
    for (int i=0; i<size; i++)
    if (list[i]) { rigid2.AddAtom(rigid.CopyAtom(i)); }
    return rigid2;
}

}//namespace PTools