Skip to content

Fix invalid escape sequences #167

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion scripts/ccp4_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
AUTHOR
Gerhard Reitmayr and Dalia Daujotyte, 2011.
'''
from pathlib import Path
from pymol import cmd
import re


def parseCONTACTContacts(f):
# Lys 24A ca Asp 263D CG ... 4.94 [ -1B ] 3: -X, Y+1/2, -Z+1/2
conParser = re.compile("(\S*)\s*(\d+)([A-Z])\s*(\w+)")
conParser = re.compile(r"(\S*)\s*(\d+)([A-Z])\s*(\w+)")
s1 = []
s2 = []
for line in f:
Expand Down Expand Up @@ -73,3 +74,14 @@ def ccp4_contact(contactsfile, selName1="source", selName2="target"):
cmd.select(selName2 + "_atom", atomSel)

cmd.extend("ccp4_contact", ccp4_contact)


def test_ccp4_contact():
datadir = Path(__file__).parents[1] / "files_for_examples"
cmd.reinitialize()
cmd.fab("PCQAFSISGKQKGFEDSRGTL", chain="A", resi=80)
ccp4_contact(f"{datadir}/2c7r.contact", selName1="sel1", selName2="sel2")
assert cmd.count_atoms("sel1_res") == 128
assert cmd.count_atoms("sel1_atom") == 20
assert cmd.count_atoms("sel2_res") == 128
assert cmd.count_atoms("sel2_atom") == 20
22 changes: 20 additions & 2 deletions scripts/ccp4_ncont.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
AUTHOR
Gerhard Reitmayr and Dalia Daujotyte, 2009.
'''
from __future__ import print_function
from pathlib import Path
from pymol import cmd
import re


def parseNCONTContacts(f):
# /1/B/ 282(PHE). / CE1[ C]: /1/E/ 706(GLN). / O [ O]: 3.32
# * in the second group is needed when chain code is blank
conParser = re.compile("\s*/(\d+)/([a-zA-Z0-9]*)/\s*(\d+).*?/\s*([a-zA-Z0-9]*).*?:")
conParser = re.compile(r"\s*/(\d+)/([a-zA-Z0-9]*)/\s*(\d+).*?/\s*([a-zA-Z0-9]*).*?:")
mode = 0
s1 = []
s2 = []
Expand Down Expand Up @@ -83,3 +83,21 @@ def ccp4_ncont(contactsfile, selName1="source", selName2="target"):
cmd.select(selName2 + "_atom", atomSel)

cmd.extend("ccp4_ncont", ccp4_ncont)


def test_ccp4_ncont():
datadir = Path(__file__).parents[1] / "files_for_examples"
cmd.reinitialize()
cmd.fab("PCQAFSISGKQKGFEDSRGTL", "m1", chain="A", resi=80)
cmd.fnab("GCTGAC", "m2", dbl_helix=False)
cmd.remove("hydro")
cmd.alter("m2", "chain = 'C'")
cmd.alter("m2", "resv += 407")
cmd.alter("m2 & name O1P", "name = 'OP1'")
cmd.alter("m2 & name O2P", "name = 'OP2'")
cmd.alter("m2 & name O3P", "name = 'OP3'")
ccp4_ncont(f"{datadir}/2c7r.ncont", selName1="sel1", selName2="sel2")
assert cmd.count_atoms("sel1_res") == 23
assert cmd.count_atoms("sel1_atom") == 5
assert cmd.count_atoms("sel2_res") == 104
assert cmd.count_atoms("sel2_atom") == 16
24 changes: 23 additions & 1 deletion scripts/flatten_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def flatten_obj(name="",selection="",state=0,rename=0,quiet=1,chain_map=""):
cmd.create(prefix, obj, state, 1)

# renumber all states
statere = re.compile("^%s_(.*)_(\d+)$" % metaprefix) # matches split object names
statere = re.compile(r"^%s_(.*)_(\d+)$" % metaprefix) # matches split object names

warn_lowercase = False

Expand Down Expand Up @@ -334,3 +334,25 @@ def flatten_obj(name="",selection="",state=0,rename=0,quiet=1,chain_map=""):
# tab-completion of arguments
cmd.auto_arg[0]['flatten_obj'] = [ cmd.object_sc, 'name or selection', '']
cmd.auto_arg[1]['flatten_obj'] = [ cmd.object_sc, 'selection', '']


def test_flatten_obj__rename0():
cmd.reinitialize()
cmd.fab("ACD", "m1", chain="C")
cmd.fab("DEF", "m2", chain="C")
flatten_obj("m3", "m1 | m2", rename=0)
assert cmd.count_atoms("m3") == 80
assert cmd.count_atoms("m3 & resi 2") == 26
assert cmd.get_chains("m3") == ["A", "C"]


def test_flatten_obj__rename1():
cmd.reinitialize()
cmd.fab("ACD", "m1", chain="C")
cmd.fab("DEF", "m2", chain="C")
flatten_obj("m3", "m1 | m2", rename=1, chain_map="foo")
assert cmd.get_chains("m3") == ["A", "B"]
assert dict(stored.foo) == {
"A": ("m1", 1, "C"),
"B": ("m2", 1, "C"),
}
4 changes: 2 additions & 2 deletions scripts/forster_distance_calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
r'''
Described at PyMOL wiki:
http://www.pymolwiki.org/index.php/forster_distance_calculator

Expand Down Expand Up @@ -77,7 +77,7 @@ def forster(D_Exi="ATTO488Exi.txt", D_Emi="ATTO488Emi.txt", A_Exi="ATTO590Exi.tx
print("The .plt should be opened with gnuplot to make the graphs.")
print("The created graphs are .eps files.")
print("They can be converted to pdf with the program: epstopdf or eps2pdf")
print('Part of LaTeX: C:\Program Files (x86)\MiKTeX 2.9\miktex' + "\\" + "bin")
print(r'Part of LaTeX: C:\Program Files (x86)\MiKTeX 2.9\miktex' + "\\" + "bin")
print("Or download here: http://tinyurl.com/eps2pdf")

DonorEmi = open(D_Emi, "r")
Expand Down
14 changes: 7 additions & 7 deletions scripts/plot_noe.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def plot_noe(filename, line_color=None, line_width='1.0', advanced_coloring=0, s
if advanced_coloring == 1:
cmd.set("group_auto_mode", 2)

rgx_assi = re.compile("\s*[asignASIGN]+\s+.*")
rgx_or = re.compile("\s*[orOR]+\s+.*")
rgx_bracket = re.compile("(\(|\))")
rgx_tick = re.compile("(\w)\'")
rgx_assi = re.compile(r"\s*[asignASIGN]+\s+.*")
rgx_or = re.compile(r"\s*[orOR]+\s+.*")
rgx_bracket = re.compile(r"(\(|\))")
rgx_tick = re.compile(r"(\w)'")

restraint_line = None
restraint_block = []
Expand All @@ -68,17 +68,17 @@ def plot_noe(filename, line_color=None, line_width='1.0', advanced_coloring=0, s
for line in open(filename):
if rgx_assi.match(line):
if restraint_line:
restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraints_blocks.append(restraint_block)
restraint_block = []
restraint_line = line
elif rgx_or.match(line):
restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraint_line = line
else:
restraint_line += line

restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
restraints_blocks.append(restraint_block)

for restraint_block in restraints_blocks:
Expand Down
6 changes: 3 additions & 3 deletions scripts/propka.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
r'''
Described at PyMOL wiki:
http://www.pymolwiki.org/index.php/propka

Expand Down Expand Up @@ -222,7 +222,7 @@ def getpropka(PDB="NIL", chain="*", resi="0", resn="NIL", source="upload", PDBID
assert version in ['v2.0', 'v3.0', 'v3.1'], "'version' has to be either: 'v2.0', 'v3.0', 'v3.1'"
assert source in ['ID', 'upload', 'addr', 'input_file'], "'source' has to be either: 'ID', 'upload', 'addr', 'input_file'"
if source == "upload":
assert PDB not in ['NIL'], "You always have to provide PDB path. Example: PDB=.\Results_propka\4ins2011.pdb"
assert PDB not in ['NIL'], r"You always have to provide PDB path. Example: PDB=.\Results_propka\4ins2011.pdb"
if source == "ID":
assert len(PDBID) == 4, "PDBID has to be 4 characters"
# To print out to screen for selected residues. Can be separated with "." or make ranges with "-". Example: resi="4-8.10"
Expand Down Expand Up @@ -517,7 +517,7 @@ def importpropkabonds(result_pka_pkafile):

def createdirs():
if platform.system() == 'Windows':
Newdir = os.getcwd() + "\Results_propka\\"
Newdir = os.getcwd() + "\\Results_propka\\"
if platform.system() == 'Linux':
Newdir = os.getcwd() + "/Results_propka/"
if not os.path.exists(Newdir):
Expand Down
6 changes: 3 additions & 3 deletions scripts/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

"""Homogeneous Transformation Matrices and Quaternions.
r"""Homogeneous Transformation Matrices and Quaternions.

A library for calculating 4x4 matrices for translating, rotating, reflecting,
scaling, shearing, projecting, orthogonalizing, and superimposing arrays of
Expand Down Expand Up @@ -883,7 +883,7 @@ def orthogonalization_matrix(lengths, angles):


def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True):
"""Return affine transform matrix to register two point sets.
r"""Return affine transform matrix to register two point sets.

v0 and v1 are shape (ndims, \*) arrays of at least ndims non-homogeneous
coordinates, where ndims is the dimensionality of the coordinate space.
Expand Down Expand Up @@ -992,7 +992,7 @@ def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True):


def superimposition_matrix(v0, v1, scale=False, usesvd=True):
"""Return matrix to transform given 3D point set into second point set.
r"""Return matrix to transform given 3D point set into second point set.

v0 and v1 are shape (3, \*) or (4, \*) arrays of at least 3 points.

Expand Down
2 changes: 1 addition & 1 deletion scripts/wfmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def readOBJ(self, file):
if os.path.exists(file):
input = open(file, 'r')
for line in input:
dat = re.split("\s+", line)
dat = re.split(r"\s+", line)

# Find vertex line
if line[0] == 'v' and line[1] != 't' and line[1] != 'n':
Expand Down