File: SConscript-main.py

package info (click to toggle)
pdb2pqr 2.1.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 44,408 kB
  • sloc: python: 44,146; cpp: 9,839; xml: 9,092; sh: 81; makefile: 47; ansic: 36
file content (349 lines) | stat: -rw-r--r-- 13,444 bytes parent folder | download | duplicates (3)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import distutils.sysconfig

import os
from defaults import *
import atexit

Export('codePath')

config_file = 'build_config.py'

gcv = distutils.sysconfig.get_config_var

vars = Variables(['.variables.cache', config_file], ARGUMENTS)

vars.Add(PathVariable('PREFIX',
                      'Install directory',
                      defaultPrefix,
                      PathVariable.PathAccept))

vars.Add('URL', "Sets the url of pdb2pqr's web interface.", defaultURL)

vars.Add('OPAL', 'Sets the url of a pdb2pqr opal service.', '')
vars.Add('APBS_OPAL', 'Sets the url of a apbs opal service.', '')

vars.Add(PathVariable('APBS',
                      'Location of the APBS binary if installed',
                      '',
                      PathVariable.PathAccept))

vars.Add('MAX_ATOMS', 'Sets the maximum number of atoms in a protein for non-Opal job submission. '
					  'Only affects web tools', 10000, None, int)

vars.Add(BoolVariable('BUILD_PDB2PKA',
					  'Set to False to skip building ligand and pdb2pka support. Requires numpy.',
					  True))

vars.Add(BoolVariable('REBUILD_SWIG',
					  'Set to True to rebuild the swig bindings. Requires swig on the the user path.',
					  False))

vars.Add(BoolVariable('DEBUG',
                      'Set to True to compiled components with debug headers.',
                      False))

vars.Add('EXTRA_CXXFLAGS', 'Set to add extra CXX flags to the build.', '')
vars.Add('EXTRA_LINKFLAGS', 'Set to add extra link flags to the build.', '')

#TODO: setup rebuilding of docs.
# THIS SHOULD BE A TARGET!
#AddOption('--rebuild-docs',
#        dest='docs',
#        action='store_true',
#        default=False,
#        help='Rebuild pydocs.')

#Windows: make sure we use correct target arch.
target_arch='x86_64'
import platform
arch = platform.architecture()
bit_str = arch[0]
if bit_str == '32bit':
    target_arch='x86'

if os.name == 'nt':
    tool_chain = ['default', 'mssdk']
else:
    tool_chain = ['default']

tool_chain.append('swig')

env = Environment(variables=vars,
                  MSVC_VERSION='9.0',
                  TARGET_ARCH=target_arch,
                  MSSDK_VERSION='6.0A',
                  tools=tool_chain,
                  SWIGFLAGS=['-python', '-c++'],
                  SHLIBPREFIX="",
                  SHLIBSUFFIX=gcv('SO'),
                  LDMODULESUFFIX=gcv('SO'))



python_lib = 'python' + gcv('VERSION')
env.Append(LIBS=[python_lib])
#To get swig to work on windows.
#env.Append(ENV={'PATH' : os.environ['PATH']})

if os.name == 'nt' and 'icc' not in tool_chain:
    env.Append(CXXFLAGS = ['/EHsc'])

if env['DEBUG']:
    if os.name == 'nt' and 'icc' not in tool_chain:
        env.Append(CXXFLAGS = ['/DEBUG'])
    else:
        env.MergeFlags('-g')

if env['EXTRA_CXXFLAGS']:
    env.Append(CXXFLAGS = [env['EXTRA_CXXFLAGS']])

if env['EXTRA_LINKFLAGS']:
    env.Append(LINKFLAGS = [env['EXTRA_LINKFLAGS']])

if 'LDFLAGS' in os.environ:
    env.Append(LINKFLAGS = os.environ['LDFLAGS'])
    
if os.name == 'nt':
    #Check to see if we are running in a virtualenv
    if hasattr(sys, 'real_prefix'):
        python_root = sys.real_prefix
    else:
        python_root = sys.prefix
    python_include = os.path.join(python_root, 'include')
    python_libs = os.path.join(python_root, 'libs')
    env.Append(LIBPATH=[python_libs])
else:
    env.Append(LIBPATH=[gcv('LIBDIR')])

Export('env')

prefix = env['PREFIX']
prefix = prefix.replace('\\', '/')
if not prefix.endswith('/'):
    prefix+='/'

env['PREFIX'] = prefix

Help(vars.GenerateHelpText(env))

vars.Save('.variables.cache', env)

#Not the optimal way to do this...
#Should figure out how to do it with a delete command
Clean('pdb2pqr.py', '.variables.cache')

url = env['URL']
#Not sure if this is needed.
if url is not None:
    if not url.endswith('/'):
        url += '/'
    submitAction = url+'pdb2pqr.cgi'
else:
    url = defaultURL
    #Can it always just be this?
    submitAction = 'pdb2pqr.cgi'

maxatomsStr = str(env['MAX_ATOMS'])

replacementDict = {'@WHICHPYTHON@':pythonBin,
                   '@INSTALLDIR@':prefix,
                   '@MAXATOMS@':maxatomsStr,
                   '@website@':url,
                   '@srcpath@':codePath,
                   '@PDB2PQR_VERSION@':productVersion,
                   '@action@':submitAction,
                   '@APBS_LOCATION@':env['APBS'],
                   '@APBS_OPAL_URL@':env['APBS_OPAL'],
                   '@PDB2PQR_OPAL_URL@':env['OPAL']}

#If any replacement strings change recompile those files.
#As the product version can be based on the time this may
# rebuild string replacement files after less than one minute between builds
settingsValues = env.Value(replacementDict)

#We have a separate dict for server.html.in as we need to use regex
#Regex does not play nice with some  possible user strings
#Set up regex to alternately clear tags or wipe sections
if env['OPAL'] == '':
    #Not using opal for pdb2pqr.
    print "not using opal", env['OPAL']
    withOpalRegex = r'@WITHOPAL@.*?@WITHOPAL@'
    withoutOpalRegex = '@WITHOUTOPAL@'

else:
    #Using opal for pdb2pqr.
    print "using opal", env['OPAL']
    withOpalRegex = '@WITHOPAL@'
    withoutOpalRegex = r'@WITHOUTOPAL@.*?@WITHOUTOPAL@'


serverHtmlDict = {'@website@':url,
                  '@PDB2PQR_VERSION@':productVersion,
                  '@MAXATOMS@':maxatomsStr,
                  '@action@':submitAction,
                  withOpalRegex:'',
                  withoutOpalRegex:''}

chmodAction = Chmod('$TARGET', 0755)
serverHtmlCopySub = CopySub('$TARGET', '$SOURCE', serverHtmlDict, useRegex=True)
normalCopySub = CopySub('$TARGET', '$SOURCE', replacementDict, useRegex=False)

subFiles = [('pdb2pqr.py', 'pdb2pqr.py.in', True),
            ('apbs_cgi.cgi', 'apbs_cgi.py', True),
            ('visualize.cgi', 'visualize.py', True),
            ('querystatus.cgi', 'querystatus.py', True),
            ('src/aconf.py', 'src/aconf.py.in', False),
            ('html/server.html', 'html/server.html.in', False)]

compile_targets = []

for target, source, chmod in subFiles:
    actions = [normalCopySub] if target != 'html/server.html' else [serverHtmlCopySub]
    if chmod:
        actions.append(chmodAction)
    result = env.Command(target, source, actions)
    compile_targets.append(result)
    if target == 'pdb2pqr.py':
        pdb2pqr = result
        Export('pdb2pqr')
    Default(result)
    Depends(result, settingsValues)

Default(env.Command('pdb2pqr.cgi', 'pdb2pqr.py', Copy('$TARGET', '$SOURCE')))

#Check to see why we can't build pdb2pka.
numpy_error = False
if env['BUILD_PDB2PKA']:
    try:
        import numpy
    except ImportError:
        print 'WARNING: PDB2PKA build skipped, numpy not installed. Ligand support will not be available.'
        numpy_error = True

    if not numpy_error:
        import distutils

        env.Append(CPPPATH=[distutils.sysconfig.get_python_inc(), numpy.get_include()])

        alg_srcs = ['pdb2pka/substruct/Algorithms.cpp']

        algorithms_pyc = env.LoadableModule('pdb2pka/substruct/Algorithms', ['pdb2pka/substruct/Algorithms.cpp'])

        Default(algorithms_pyc)
        Alias('algorithms', algorithms_pyc)
        compile_targets.append(algorithms_pyc)

        if os.name == 'nt':
            alg_msvs_env = env.Clone(MSVSBUILDCOM='cd .. && '+pythonBin+' scons/scons.py algorithms DEBUG=True',
                                     MSVSCLEANCOM='cd .. && '+pythonBin+' scons/scons.py -c algorithms',
                                     MSVSREBUILDCOM='cd .. && '+pythonBin+' scons/scons.py -c algorithms && '+pythonBin+' scons/scons.py algorithms DEBUG=True')

            algorithms_project = alg_msvs_env.MSVSProject(target = 'msvs/Algorithms' + env['MSVSPROJECTSUFFIX'],
                                                          auto_build_solution=0,
                                                          srcs = ['../pdb2pka/substruct/Algorithms.cpp'],
                                                          buildtarget = algorithms_pyc[0],
                                                          variant = 'Debug|x64')
            Alias('msvs', algorithms_project)

        pmc_srcs = ['pdb2pka/pMC_mult.cpp', 'pdb2pka/pMC_mult_wrap.cpp']

        if env['REBUILD_SWIG']:
            pmc_pyc = env.LoadableModule('pdb2pka/_pMC_mult', ['pdb2pka/pMC_mult.cpp', 'pdb2pka/pMC_mult.i'])
            build_swig = ' REBUILD_SWIG=True'
        else:
            pmc_pyc = env.LoadableModule('pdb2pka/_pMC_mult', ['pdb2pka/pMC_mult.cpp', 'pdb2pka/pMC_mult_wrap.cpp'])
            build_swig = ' '

        Default(pmc_pyc)
        Alias('pmc_mult', pmc_pyc)
        compile_targets.append(pmc_pyc)

        if os.name == 'nt':
            pmc_msvs_env = env.Clone(MSVSBUILDCOM='cd .. && '+pythonBin+' scons/scons.py pmc_mult DEBUG=True'+build_swig,
                                     MSVSCLEANCOM='cd .. && '+pythonBin+' scons/scons.py -c pmc_mult',
                                     MSVSREBUILDCOM='cd .. && '+pythonBin+' scons/scons.py -c pmc_mult && '+pythonBin+' scons/scons.py pmc_mult DEBUG=True'+build_swig)

            pmc_mult_project = pmc_msvs_env.MSVSProject(target = 'msvs/pMC_mult' + env['MSVSPROJECTSUFFIX'],
                                                        auto_build_solution=0,
                                                        srcs = ['../pdb2pka/pMC_mult.cpp', '../pdb2pka/pMC_mult_wrap.cpp'],
                                                        incs = ['../pdb2pka/pMC_mult.h'],
                                                        resources = ['../pdb2pka/pMC_mult.i'],
                                                        buildtarget = pmc_pyc[0],
                                                        variant = 'Debug|x64')
            Alias('msvs', pmc_mult_project)

            pdb2pqr_sln = env.MSVSSolution(target = 'msvs/pdb2pqr' + env['MSVSSOLUTIONSUFFIX'],
                            projects = [pmc_mult_project, algorithms_project],
                            variant = 'Debug|x64')

            Alias('msvs', pdb2pqr_sln)

SConscript('tests/SConscript')

SConscript('SConscript-install.py', exports='env compile_targets')

SConscript('SConscript-error.py')

def print_default_message(target_list):
    target_list = map(str, target_list)
    if any('test' in x for x in target_list):
        return
    if GetOption("clean"):
        return
    if not GetOption("help"):

        print
        print 'TARGETS:', target_list
        print
        print '========================'
        print 'Configuration Parameters'
        print '========================'
        print
        print 'Version:', productVersion
        print 'Install directory:', env['PREFIX']
        if numpy_error:
            print
            print 'WARNING: PDB2PKA build skipped, numpy not installed. Ligand support will not be available.'
            print
        else:
            print 'pdb2pka and ligand support:', env['BUILD_PDB2PKA']
        print 'Path to the website directory:', url
        if env['OPAL'] == '':
            print 'PDB2PQR jobs run via the web interface will be forked on the server.'
        else:
            print 'PDB2PQR jobs run via the web interface will be run via opal at', env['OPAL']
    else:
        print
        print 'Run "python scons/scons.py" to build pdb2pqr.'

    print
    print 'The preferred way to configure the build is by editing the file', config_file
    print
    print 'Run scons with the python that you intend to use with pdb2pqr.'
    print 'For example: "/opt/bin/python scons/scons.py" will setup pdb2pqr to be run with /opt/bin/python'

    if 'install' not in target_list:
        print
        print 'Run "python scons/scons.py install" to install pdb2pqr in', env['PREFIX']

    print
    print 'Run "python scons/scons.py basic-test" for a basic functionality test'
    print 'Run "python scons/scons.py advanced-test" for a single test of ligand and PROPKA support. Requires numpy and PDB2PKA support compiled.'
    print 'Run "python scons/scons.py complete-test" for a complete test of all functionality EXCEPT PDB2PKA. Requires numpy and PDB2PKA support compiled.'
    print 'Run "python scons/scons.py pdb2pka-test" for a test of PDB2PKA functionality.'
    print '    Requires numpy, PDB2PKA support compiled AND the APBS python libraries compiled and installed in the pdb2pka directory.'

    print
    print 'To setup a web service create a symbolic link to', env['PREFIX'], 'that enables you to view', env['URL'],'after running "scons/scons.py install"'
    print
    print 'Run "python scons/scons.py msvs" to build Visual Studio projects for the Algorithms and pMC_mult modules.'
    print 'VS project generation is not well supported in scons. Resulting projects should build using NMAKE but cannot be used for debugging.'
    print 'The resulting projects will need to modified to use VS natively to compile the code or debug.'


    if 'install' in target_list:
        print
        print 'pdb2pqr installed in', env['PREFIX']


atexit.register(print_default_message, BUILD_TARGETS)