Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to python 3 #41

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
43 changes: 43 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10",]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build and install with setuptools
run: |
python setup.py install
- name: Test with pytest
run: |
pytest example_scripts/
76 changes: 38 additions & 38 deletions example_scripts/test_build.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
from pmx import *
from pmx import Molecule, Chain
from pmx.builder import build_dna_strand


# start a peptide chain from an amino acid
mol = Molecule().new_aa( "ALA" ) # build alanine
c = Chain( residues = [ mol ] ) # initialize chain
c.nbuild("T") # extend at n-terminus
c.cbuild("R") # extend at c-terminus
c.write('TAR.pdb') # write pdb file
def test_build():
# start a peptide chain from an amino acid
mol = Molecule().new_aa( "ALA" ) # build alanine
c = Chain( residues = [ mol ] ) # initialize chain
c.nbuild("T") # extend at n-terminus
c.cbuild("R") # extend at c-terminus
c.write('TAR.pdb') # write pdb file

# build a peptide chain from sequence
# build a peptide chain from sequence

sequence = "FRTLKNCWQ"
c = Chain().create( sequence )
c.write("extended.pdb")
sequence = "FRTLKNCWQ"
c = Chain().create( sequence )
c.write("extended.pdb")

for resi in c.residues:
resi.set_phi( -57, True )
resi.set_psi( -47, True )
c.write("helix_pep.pdb")
for resi in c.residues:
resi.set_phi( -57, True )
resi.set_psi( -47, True )
c.write("helix_pep.pdb")

# fusing two chains
seq = "LMNFRTS"
c2 = Chain().create(seq)
c.fuse( c2 )
c.write("fused_pep.pdb")
# fusing two chains
seq = "LMNFRTS"
c2 = Chain().create(seq)
c.fuse( c2 )
c.write("fused_pep.pdb")


# create repeating seuqences
# create repeating seuqences



rep_seq = "HEATLLFT"
c = Chain().create( rep_seq ) # start with new chain
new_chain = c.copy()
rep_seq = "HEATLLFT"
c = Chain().create( rep_seq ) # start with new chain
new_chain = c.copy()

for i in range(5):
c.fuse( new_chain.copy() )
c.write("rep_pep.pdb")
print c.sequence()
helical_residues = c.fetch_residues(["HIS","GLU","ALA","THR","LEU"])
for resi in helical_residues:
resi.set_phi( -57, True )
resi.set_psi( -47, True )
c.write("repeat_helix.pdb")
for i in range(5):
c.fuse( new_chain.copy() )
c.write("rep_pep.pdb")
print(c.sequence())
helical_residues = c.fetch_residues(["HIS","GLU","ALA","THR","LEU"])
for resi in helical_residues:
resi.set_phi( -57, True )
resi.set_psi( -47, True )
c.write("repeat_helix.pdb")


# building a DNA strand
from pmx.builder import *
model = build_dna_strand("ACGTGTCA")
model.write("dna.pdb")

# building a DNA strand
model = build_dna_strand("ACGTGTCA")
model.write("dna.pdb")
63 changes: 32 additions & 31 deletions example_scripts/test_edit.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import sys, os
from pmx import *
from pmx import Model, Chain

seq1 = 'klrtsfcvnme'*2
seq2 = 'irtiervcywq'*2

def test_edit():
seq1 = 'klrtsfcvnme'*2
seq2 = 'irtiervcywq'*2

c1 = Chain().create( seq1.upper() )
c2 = Chain().create( seq2.upper() )
c1.set_chain_id('A')
c2.set_chain_id('B')
c2.translate( [20,0,0] )
m = Model(chains = [c1,c2] )
m.write('protein.pdb')

m = Model('protein.pdb')
c1 = Chain().create( seq1.upper() )
c2 = Chain().create( seq2.upper() )
c1.set_chain_id('A')
c2.set_chain_id('B')
c2.translate( [20,0,0] )
m = Model(chains = [c1,c2] )
m.write('protein.pdb')

for atom in m.atoms:
print atom.id, atom.name, atom.resname

for resi in m.residues:
if resi.resname in ['ALA','SER']: # select some residues
print resi
for atom in resi.atoms:
print atom.bfac # print some properties
m = Model('protein.pdb')

for atom in m.atoms:
print(atom.id, atom.name, atom.resname)

for c in m.chains:
print c.id, len(c.residues), len(c.atoms) # print chain id, number of
# residues and number of atoms
for resi in m.residues:
if resi.resname in ['ALA','SER']: # select some residues
print(resi)
for atom in resi.atoms:
print(atom.bfac) # print some properties

chainB = m.chdic['B'] # select chain
for atom in chainB.atoms:
print atom.occ

for c in m.chains:
print(c.id, len(c.residues), len(c.atoms)) # print chain id, number of
# residues and number of atoms

resl = m.fetch_residues(["LEU","PHE"])
for r in resl:
print 'leu_or_phe:', r
chainB = m.chdic['B'] # select chain
for atom in chainB.atoms:
print(atom.occ)

resl = m.fetch_residues(["LEU","PHE"], inv = True)
for r in resl:
print 'not leu_or_phe:', r

resl = m.fetch_residues(["LEU","PHE"])
for r in resl:
print('leu_or_phe:', r)

resl = m.fetch_residues(["LEU","PHE"], inv = True)
for r in resl:
print('not leu_or_phe:', r)
59 changes: 30 additions & 29 deletions example_scripts/test_ffparser.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import sys, os

from pmx.forcefield2 import *
from pmx.forcefield2 import ITPFile

top = ITPFile( sys.argv[1])
## for atom in top.atoms:
## atom.atomtypeB = 'DUM'
## atom.qB = 0
## atom.mB = atom.m
top.write('new.itp')

def test_ffparser():
top = ITPFile('./protLig_benchmark/pde2/ligands_cgenff/lig_50181001/MOL.itp')
## for atom in top.atoms:
## atom.atomtypeB = 'DUM'
## atom.qB = 0
## atom.mB = atom.m
top.write('new.itp')

## from pmx.ffparser import *
## ## from pmx.library import _aacids_dic
## rtp = RTPParser( 'ffamber99sb.rtp')
## print rtp['ALA']

## for name, entry in rtp:
## print name, entry['atoms'][0]
## print 'XXX'
## for name, entry in rtp:
## print name, entry['atoms'][0]
## ala = rtp['ALA']
## print _aacids_dic
## for aa in _aacids_dic.values():
## try:
## del rtp[aa]
## except:
## pass
## rtp.add_entry( "ala", ala )
## print "ala" in rtp
#rtp.write(sys.stdout)
#print rtp["ALA"]['bonds']
## from pmx.ffparser import *
## ## from pmx.library import _aacids_dic
## rtp = RTPParser( 'ffamber99sb.rtp')
## print rtp['ALA']

#nb = NBParser("ffamber99sbnb.itp")
#print nb
## for name, entry in rtp:
## print name, entry['atoms'][0]
## print 'XXX'
## for name, entry in rtp:
## print name, entry['atoms'][0]
## ala = rtp['ALA']
## print _aacids_dic
## for aa in _aacids_dic.values():
## try:
## del rtp[aa]
## except:
## pass
## rtp.add_entry( "ala", ala )
## print "ala" in rtp
#rtp.write(sys.stdout)
#print rtp["ALA"]['bonds']

#nb = NBParser("ffamber99sbnb.itp")
#print nb
13 changes: 8 additions & 5 deletions example_scripts/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
from pmx import *
from pmx.ndx import *

m = Model( "gmx.pdb" )
m = Model( "./protLig_benchmark/cdk2/ligands_gaff2/lig_1h1q/mol_gmx.pdb" )

import pytest
pytest.skip(allow_module_level=True)
# skip because don't have an example .ndx file

ndx = IndexFile("index.ndx")

print ndx
print ndx['Backbone']
print(ndx)
print(ndx['Backbone'])

atoms = ndx['Backbone'].select_atoms( m )
del ndx['Backbone']
Expand All @@ -17,7 +21,6 @@



print ndx
print(ndx)
#for atom in atoms:
# print atom

27 changes: 13 additions & 14 deletions example_scripts/test_insert.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import sys, os
from pmx import *
from pmx import Model, Chain

## c = Chain().create("ALKIRTS")
def test_insert():
c = Chain().create("ALKIRTS")
m = Model("./protLig_benchmark/cdk2/protein_amber/protein.pdb")

## m = Model("protein.pdb")

## chB = m.chdic["B"]

## chB.insert_chain(2, c )
## m.write("ins.pdb")
c = Chain().create("ALT")
print c.atoms[0].name
del c.atoms[0] # delete list item, first atom is gone
print c.atoms[0].name # first atom is a different one now
atom = c.residues[0].atoms[0] # select first atom from the first residue
print atom.name # should be the same as above
chB = m.chdic["B"]
chB.insert_chain(2, c )
m.write("ins.pdb")

c = Chain().create("ALT")
print(c.atoms[0].name)
del c.atoms[0] # delete list item, first atom is gone
print(c.atoms[0].name) # first atom is a different one now
atom = c.residues[0].atoms[0] # select first atom from the first residue
print(atom.name) # should be the same as above
1 change: 0 additions & 1 deletion example_scripts/test_new_rot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
r.set_phi( -57, True )
r.set_psi( -47, True )
c.write('hel.pdb')

17 changes: 9 additions & 8 deletions example_scripts/test_opt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest
pytest.skip(allow_module_level=True)

import sys, os
from pmx import *

Expand All @@ -13,21 +16,19 @@


file_options = [
FileOption("-pdb", "r",["pdb"], "protein.pdb", "input pdb file"),
FileOption("-opdb", "w",["pdb","gro"], "out.pdb", "output pdb or gro file"),
FileOption("-mpdb", "r/m",["pdb","gro"], "one_of_many.pdb", "several pdb files"),
FileOption("-pdb", "r",["pdb"], "protein.pdb", "input pdb file"),
FileOption("-opdb", "w",["pdb","gro"], "out.pdb", "output pdb or gro file"),
FileOption("-mpdb", "r/m",["pdb","gro"], "one_of_many.pdb", "several pdb files"),
]

help_text = [ "This program does useful things",
"as long as you use option a,b and c",
"but not in combination with d and e"]


cmdl = Commandline( sys.argv, options = options, fileoptions = file_options, program_desc = help_text, version = "2.3")


cmdl = Commandline( sys.argv, options = options, fileoptions = file_options, program_desc = help_text, version = "2.3")

string_opt = cmdl['-s']
input_pdb = cmdl['-pdb']


string_opt = cmdl['-s']
input_pdb = cmdl['-pdb']
Loading