Re: Von HTML Knopf in Python rein
Verfasst: Mittwoch 27. April 2011, 23:15
@mzh: Falls mit "das" `os.dirname()` gemeint sein sollte: Das heisst eigentlich `os.path.dirname()`.
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
import os.path
print(os.path.dirname(os.path.abspath(__file__)))
Code: Alles auswählen
#!/usr/local/bin/python3
"""Description of the 'connect' module.
The 'connect' module prepares the BioFET-SIM calculation.
It carries out the following steps:
- Download of the PDB file
- Fixing the PDB file with PDB2PQR
- Realigning the protein structure with VMD
- From the realignment, the dimensions are obtained
- Calculation of overall charge with PROPKA 3.
"""
# NOTE:
# - Calls all functions in order to obtain the
# charge, charge-carrier number and dimensions
# of the protein.
# Default modules
import sys
import os
import time
from os.path import splitext
from subprocess import call
# Custom modules
import propka
import getCharge
import getDimension
# Builtin modules
#import realign
#import getPointCharges
#import getCharge
from signature import signature
from tests import hasExt
from parse import parse
# ************************************************************
# ************************************************************
# SETUP
def setup(pdbfile):
"""Setting up the run.
The function handles the submitted argument, ie. it checks
if there is an extension or not. Incase it is missing, it is
appended, incase it is present, the extension remains.
setup(<PDB_ID[.pdb]>) --> target
The return value is an uppercase string including the '.pdb'
extension.
"""
signature('SETUP')
# Handle the case with/without extension in the argument
if hasExt(pdbfile):
target = pdbfile.upper()
else:
target = pdbfile.upper() + '.pdb'
return target
def getPDB(target):
"""Obtain the PDB file.
The 'target' argument is the correct file name, including
the '.pdb' extension, eg. '1AVD.pdb'.
The file is written to disc after download."""
print("Provided PDB file: " + target)
print("Requesting PDB file: " + target)
#call(['wget', 'http://www.pdb.org/pdb/files/'\
# + target])
os.system("wget http://www.pdb.org/pdb/files/"\
+ target)
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# PDB2PQR Part
def callPDB2PQR(target):
signature('PDB2PQR')
call(['pdb2pqr.py', '-v', '--ff=CHARMM', target,\
splitext(target)[0] + '-out.pqr'])
#os.system('pdb2pqr.py -v --ff=CHARMM ' + target\
# + ' ' + splitext(target)[0] + '-out.pqr')
print('PDB2PQR done.')
print()
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# VMD Part
def callVMD(target):
signature('VMD')
#call(['align.py', target])
os.system('realign.py ' + target[0:4] + '-out.pqr')
print('VMD done.')
print()
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# PROPKA Part
def callPropka3(target):
signature('PROPKA')
#call(['cp', splitext(target)[0] + '-out.pqr',\
# splitext(target)[0] + '-out.pdb'])
#call(['propka.py', splitext(target)[0] + '-out.pdb'])
#os.system('cp ' + splitext(target)[0] + '-out.pqr'\
# ' ' + splitext(target)[0] + '-out.pdb')
if os.system('propka.py ' + splitext(target)[0] +\
'-out-new.pdb') == 0:
print('Propka 3 done.')
print()
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# BOX Part
def callBox(target):
signature('BOX')
dim = getDimension.BoxPDB(target)
print(dim.boxIt())
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# COLLECT Part
def collectData(pH, target):
signature("COLLECTING DATA")
charge = getCharge.getCharge(pH, target)
print('Charge at pH {0}: {1}'.format(pH, charge[1]))
print()
# ------------------------------------------------------------
# ************************************************************
# ************************************************************
# Entry point of Python.
try:
# Get the argument
pdbfile = sys.argv[1]
target = setup(pdbfile)
# Download
getPDB(target)
# OUT: 'PDB.pdb'
# Correction
# IN: 'PDB.pdb'
callPDB2PQR(target)
# OUT: 'PDB-out.pqr'
# Realignment
# IN: 'PDB-out.pqr'
callVMD(target)
# OUT: 'PDB-out-new.pdb'
# Charging
# IN: 'PDB-out-new.pdb'
callPropka3(target)
# OUT: 'PDB-out-new.pka'
if 1:
# pH=7
parse(target)
collectData(7, target)
else:
for i in range(1,15):
collectData(i, target)
print(callBox(target))
except IndexError:
if len(sys.argv) == 1:
print("No argument provided.")
print("$ connect.py <PDB>")
# End of the program.
# ************************************************************
# ************************************************************