Skip to content

Commit 6108ee4

Browse files
authored
Merge pull request #167 from Pymol-Scripts/fix-invalid-escape-sequences
Fix invalid escape sequences
2 parents ab965cc + d867d29 commit 6108ee4

File tree

8 files changed

+72
-20
lines changed

8 files changed

+72
-20
lines changed

scripts/ccp4_contact.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
AUTHOR
2424
Gerhard Reitmayr and Dalia Daujotyte, 2011.
2525
'''
26+
from pathlib import Path
2627
from pymol import cmd
2728
import re
2829

2930

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

7576
cmd.extend("ccp4_contact", ccp4_contact)
77+
78+
79+
def test_ccp4_contact():
80+
datadir = Path(__file__).parents[1] / "files_for_examples"
81+
cmd.reinitialize()
82+
cmd.fab("PCQAFSISGKQKGFEDSRGTL", chain="A", resi=80)
83+
ccp4_contact(f"{datadir}/2c7r.contact", selName1="sel1", selName2="sel2")
84+
assert cmd.count_atoms("sel1_res") == 128
85+
assert cmd.count_atoms("sel1_atom") == 20
86+
assert cmd.count_atoms("sel2_res") == 128
87+
assert cmd.count_atoms("sel2_atom") == 20

scripts/ccp4_ncont.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
AUTHOR
2424
Gerhard Reitmayr and Dalia Daujotyte, 2009.
2525
'''
26-
from __future__ import print_function
26+
from pathlib import Path
2727
from pymol import cmd
2828
import re
2929

3030

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

8585
cmd.extend("ccp4_ncont", ccp4_ncont)
86+
87+
88+
def test_ccp4_ncont():
89+
datadir = Path(__file__).parents[1] / "files_for_examples"
90+
cmd.reinitialize()
91+
cmd.fab("PCQAFSISGKQKGFEDSRGTL", "m1", chain="A", resi=80)
92+
cmd.fnab("GCTGAC", "m2", dbl_helix=False)
93+
cmd.remove("hydro")
94+
cmd.alter("m2", "chain = 'C'")
95+
cmd.alter("m2", "resv += 407")
96+
cmd.alter("m2 & name O1P", "name = 'OP1'")
97+
cmd.alter("m2 & name O2P", "name = 'OP2'")
98+
cmd.alter("m2 & name O3P", "name = 'OP3'")
99+
ccp4_ncont(f"{datadir}/2c7r.ncont", selName1="sel1", selName2="sel2")
100+
assert cmd.count_atoms("sel1_res") == 23
101+
assert cmd.count_atoms("sel1_atom") == 5
102+
assert cmd.count_atoms("sel2_res") == 104
103+
assert cmd.count_atoms("sel2_atom") == 16

scripts/flatten_obj.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def flatten_obj(name="",selection="",state=0,rename=0,quiet=1,chain_map=""):
277277
cmd.create(prefix, obj, state, 1)
278278

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

282282
warn_lowercase = False
283283

@@ -334,3 +334,25 @@ def flatten_obj(name="",selection="",state=0,rename=0,quiet=1,chain_map=""):
334334
# tab-completion of arguments
335335
cmd.auto_arg[0]['flatten_obj'] = [ cmd.object_sc, 'name or selection', '']
336336
cmd.auto_arg[1]['flatten_obj'] = [ cmd.object_sc, 'selection', '']
337+
338+
339+
def test_flatten_obj__rename0():
340+
cmd.reinitialize()
341+
cmd.fab("ACD", "m1", chain="C")
342+
cmd.fab("DEF", "m2", chain="C")
343+
flatten_obj("m3", "m1 | m2", rename=0)
344+
assert cmd.count_atoms("m3") == 80
345+
assert cmd.count_atoms("m3 & resi 2") == 26
346+
assert cmd.get_chains("m3") == ["A", "C"]
347+
348+
349+
def test_flatten_obj__rename1():
350+
cmd.reinitialize()
351+
cmd.fab("ACD", "m1", chain="C")
352+
cmd.fab("DEF", "m2", chain="C")
353+
flatten_obj("m3", "m1 | m2", rename=1, chain_map="foo")
354+
assert cmd.get_chains("m3") == ["A", "B"]
355+
assert dict(stored.foo) == {
356+
"A": ("m1", 1, "C"),
357+
"B": ("m2", 1, "C"),
358+
}

scripts/forster_distance_calculator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''
1+
r'''
22
Described at PyMOL wiki:
33
http://www.pymolwiki.org/index.php/forster_distance_calculator
44
@@ -77,7 +77,7 @@ def forster(D_Exi="ATTO488Exi.txt", D_Emi="ATTO488Emi.txt", A_Exi="ATTO590Exi.tx
7777
print("The .plt should be opened with gnuplot to make the graphs.")
7878
print("The created graphs are .eps files.")
7979
print("They can be converted to pdf with the program: epstopdf or eps2pdf")
80-
print('Part of LaTeX: C:\Program Files (x86)\MiKTeX 2.9\miktex' + "\\" + "bin")
80+
print(r'Part of LaTeX: C:\Program Files (x86)\MiKTeX 2.9\miktex' + "\\" + "bin")
8181
print("Or download here: http://tinyurl.com/eps2pdf")
8282

8383
DonorEmi = open(D_Emi, "r")

scripts/plot_noe.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def plot_noe(filename, line_color=None, line_width='1.0', advanced_coloring=0, s
5656
if advanced_coloring == 1:
5757
cmd.set("group_auto_mode", 2)
5858

59-
rgx_assi = re.compile("\s*[asignASIGN]+\s+.*")
60-
rgx_or = re.compile("\s*[orOR]+\s+.*")
61-
rgx_bracket = re.compile("(\(|\))")
62-
rgx_tick = re.compile("(\w)\'")
59+
rgx_assi = re.compile(r"\s*[asignASIGN]+\s+.*")
60+
rgx_or = re.compile(r"\s*[orOR]+\s+.*")
61+
rgx_bracket = re.compile(r"(\(|\))")
62+
rgx_tick = re.compile(r"(\w)'")
6363

6464
restraint_line = None
6565
restraint_block = []
@@ -68,17 +68,17 @@ def plot_noe(filename, line_color=None, line_width='1.0', advanced_coloring=0, s
6868
for line in open(filename):
6969
if rgx_assi.match(line):
7070
if restraint_line:
71-
restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
71+
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
7272
restraints_blocks.append(restraint_block)
7373
restraint_block = []
7474
restraint_line = line
7575
elif rgx_or.match(line):
76-
restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
76+
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
7777
restraint_line = line
7878
else:
7979
restraint_line += line
8080

81-
restraint_block.append(rgx_tick.sub("\g<1>^", rgx_bracket.sub(" ", restraint_line)))
81+
restraint_block.append(rgx_tick.sub(r"\g<1>^", rgx_bracket.sub(" ", restraint_line)))
8282
restraints_blocks.append(restraint_block)
8383

8484
for restraint_block in restraints_blocks:

scripts/propka.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''
1+
r'''
22
Described at PyMOL wiki:
33
http://www.pymolwiki.org/index.php/propka
44
@@ -222,7 +222,7 @@ def getpropka(PDB="NIL", chain="*", resi="0", resn="NIL", source="upload", PDBID
222222
assert version in ['v2.0', 'v3.0', 'v3.1'], "'version' has to be either: 'v2.0', 'v3.0', 'v3.1'"
223223
assert source in ['ID', 'upload', 'addr', 'input_file'], "'source' has to be either: 'ID', 'upload', 'addr', 'input_file'"
224224
if source == "upload":
225-
assert PDB not in ['NIL'], "You always have to provide PDB path. Example: PDB=.\Results_propka\4ins2011.pdb"
225+
assert PDB not in ['NIL'], r"You always have to provide PDB path. Example: PDB=.\Results_propka\4ins2011.pdb"
226226
if source == "ID":
227227
assert len(PDBID) == 4, "PDBID has to be 4 characters"
228228
# To print out to screen for selected residues. Can be separated with "." or make ranges with "-". Example: resi="4-8.10"
@@ -517,7 +517,7 @@ def importpropkabonds(result_pka_pkafile):
517517

518518
def createdirs():
519519
if platform.system() == 'Windows':
520-
Newdir = os.getcwd() + "\Results_propka\\"
520+
Newdir = os.getcwd() + "\\Results_propka\\"
521521
if platform.system() == 'Linux':
522522
Newdir = os.getcwd() + "/Results_propka/"
523523
if not os.path.exists(Newdir):

scripts/transformations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3131
# POSSIBILITY OF SUCH DAMAGE.
3232

33-
"""Homogeneous Transformation Matrices and Quaternions.
33+
r"""Homogeneous Transformation Matrices and Quaternions.
3434
3535
A library for calculating 4x4 matrices for translating, rotating, reflecting,
3636
scaling, shearing, projecting, orthogonalizing, and superimposing arrays of
@@ -883,7 +883,7 @@ def orthogonalization_matrix(lengths, angles):
883883

884884

885885
def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True):
886-
"""Return affine transform matrix to register two point sets.
886+
r"""Return affine transform matrix to register two point sets.
887887
888888
v0 and v1 are shape (ndims, \*) arrays of at least ndims non-homogeneous
889889
coordinates, where ndims is the dimensionality of the coordinate space.
@@ -992,7 +992,7 @@ def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True):
992992

993993

994994
def superimposition_matrix(v0, v1, scale=False, usesvd=True):
995-
"""Return matrix to transform given 3D point set into second point set.
995+
r"""Return matrix to transform given 3D point set into second point set.
996996
997997
v0 and v1 are shape (3, \*) or (4, \*) arrays of at least 3 points.
998998

scripts/wfmesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def readOBJ(self, file):
4242
if os.path.exists(file):
4343
input = open(file, 'r')
4444
for line in input:
45-
dat = re.split("\s+", line)
45+
dat = re.split(r"\s+", line)
4646

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

0 commit comments

Comments
 (0)