Compare 62beac9 ... +4 ... f2a94fd


@@ -1,12 +1,13 @@
Loading
1 -
import logging as log
2 -
import os
3 1
import base64
4 2
import json
3 +
import logging as log
4 +
import os
5 +
5 6
import numpy as np
6 -
from paprika.restraints import DAT_restraint
7 -
from parmed.amber import AmberParm
8 7
from parmed import Structure
8 +
from parmed.amber import AmberParm
9 9
10 +
from paprika.restraints import DAT_restraint
10 11
11 12
# https://stackoverflow.com/questions/27909658/json-encoder-and-decoder-for-complex-numpy-arrays
12 13
# https://stackoverflow.com/a/24375113/901925
@@ -63,7 +64,6 @@
Loading
63 64
        elif isinstance(obj, (np.ndarray,)):
64 65
            return obj.tolist()
65 66
66 -
67 67
        # Let the base class default method raise the TypeError
68 68
        # return json.JSONEncoder(self, obj)
69 69
        return super(NumpyEncoder, self).default(obj)
@@ -104,8 +104,21 @@
Loading
104 104
        tmp = DAT_restraint()
105 105
        tmp.__dict__ = loaded
106 106
107 -
        properties = ["mask1", "mask2", "mask3", "mask4", "topology", "instances", "custom_restraint_values",
108 -
                      "auto_apr", "continuous_apr", "attach", "pull", "release", "amber_index"]
107 +
        properties = [
108 +
            "mask1",
109 +
            "mask2",
110 +
            "mask3",
111 +
            "mask4",
112 +
            "topology",
113 +
            "instances",
114 +
            "custom_restraint_values",
115 +
            "auto_apr",
116 +
            "continuous_apr",
117 +
            "attach",
118 +
            "pull",
119 +
            "release",
120 +
            "amber_index",
121 +
        ]
109 122
        for class_property in properties:
110 123
            if f"_{class_property}" in tmp.__dict__.keys():
111 124
                tmp.__dict__[class_property] = tmp.__dict__[f"_{class_property}"]

@@ -11,15 +11,19 @@
Loading
11 11
12 12
def test_center_mask():
13 13
    """ Test that the first mask is centered """
14 -
    cb6 = pmd.load_file(os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb"))
14 +
    cb6 = pmd.load_file(
15 +
        os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb")
16 +
    )
15 17
    aligned_cb6 = zalign(cb6, ":CB6", ":BUT")
16 18
    test_coordinates = check_coordinates(aligned_cb6, ":CB6")
17 19
    assert np.allclose(test_coordinates, np.zeros(3))
18 20
19 21
20 22
def test_alignment_after_offset():
21 23
    """ Test that molecule is properly aligned after random offset. """
22 -
    cb6 = pmd.load_file(os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb"))
24 +
    cb6 = pmd.load_file(
25 +
        os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb")
26 +
    )
23 27
    random_coordinates = np.random.randint(10) * np.random.rand(1, 3)
24 28
    cb6_offset = offset_structure(cb6, random_coordinates)
25 29
    aligned_cb6 = zalign(cb6_offset, ":CB6", ":BUT")
@@ -29,8 +33,14 @@
Loading
29 33
30 34
def test_theta_after_alignment():
31 35
    """ Test that molecule is properly aligned after random offset. """
32 -
    cb6 = pmd.load_file(os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb"))
36 +
    cb6 = pmd.load_file(
37 +
        os.path.join(os.path.dirname(__file__), "../data/cb6-but/vac.pdb")
38 +
    )
33 39
    aligned_cb6 = zalign(cb6, ":CB6", ":BUT")
34 40
    assert get_theta(aligned_cb6, ":CB6", ":BUT", axis="z") == 0
35 -
    assert pytest.approx(get_theta(aligned_cb6, ":CB6", ":BUT", axis="x"), 0.001) == 1.5708
36 -
    assert pytest.approx(get_theta(aligned_cb6, ":CB6", ":BUT", axis="y"), 0.001) == 1.5708
41 +
    assert (
42 +
        pytest.approx(get_theta(aligned_cb6, ":CB6", ":BUT", axis="x"), 0.001) == 1.5708
43 +
    )
44 +
    assert (
45 +
        pytest.approx(get_theta(aligned_cb6, ":CB6", ":BUT", axis="y"), 0.001) == 1.5708
46 +
    )

@@ -11,15 +11,17 @@
Loading
11 11
12 12
# Add imports here
13 13
versions = get_versions()
14 -
__version__ = versions['version']
15 -
__git_revision__ = versions['full-revisionid']
14 +
__version__ = versions["version"]
15 +
__git_revision__ = versions["full-revisionid"]
16 16
del get_versions, versions
17 17
18 18
import logging
19 +
19 20
logger = logging.getLogger(__name__)
20 21
21 22
try:
22 23
    from simtk import openmm
24 +
23 25
    from paprika.setup import Setup
24 26
25 27
    setup = Setup
@@ -29,9 +31,10 @@
Loading
29 31
    setup = None
30 32
31 33
from paprika.analyze import Analyze
34 +
32 35
analyze = Analyze
33 36
34 37
if setup is None:
35 38
    __all__ = ["setup", "analyze"]
36 39
else:
37 -
    __all__ = ["analyze"]

@@ -296,8 +296,8 @@
Loading
296 296
    sys.neutralize = False
297 297
    sys.build()
298 298
    with open(
299 -
            os.path.join(os.path.dirname(__file__), "../data/cb6-but/REF_cb6-but-dum.rst7"),
300 -
            "r",
299 +
        os.path.join(os.path.dirname(__file__), "../data/cb6-but/REF_cb6-but-dum.rst7"),
300 +
        "r",
301 301
    ) as f:
302 302
        contents = f.read()
303 303
        reference = [float(i) for i in contents.split()[2:]]
@@ -331,9 +331,13 @@
Loading
331 331
    sys.neutralize = False
332 332
    sys.build()
333 333
334 -
    but = pmd.load_file(os.path.join(temporary_directory, sys.output_prefix + ".prmtop"))
334 +
    but = pmd.load_file(
335 +
        os.path.join(temporary_directory, sys.output_prefix + ".prmtop")
336 +
    )
335 337
    assert np.allclose(but["@H="].atoms[0].mass, 1.008)
336 338
337 339
    sys.repartition_hydrogen_mass()
338 -
    but = pmd.load_file(os.path.join(temporary_directory, sys.output_prefix + ".prmtop"))
340 +
    but = pmd.load_file(
341 +
        os.path.join(temporary_directory, sys.output_prefix + ".prmtop")
342 +
    )
339 343
    assert np.allclose(but["@H="].atoms[0].mass, 3.024)

@@ -1,4 +1,3 @@
Loading
1 -
2 1
# This file helps to compute a version number in source trees obtained from
3 2
# git-archive tarball (such as those provided by githubs download-from-tag
4 3
# feature). Distribution tarballs (built by setup.py sdist) and build
@@ -58,28 +57,32 @@
Loading
58 57
59 58
def register_vcs_handler(vcs, method):  # decorator
60 59
    """Decorator to mark a method as the handler for a particular VCS."""
60 +
61 61
    def decorate(f):
62 62
        """Store f in HANDLERS[vcs][method]."""
63 63
        if vcs not in HANDLERS:
64 64
            HANDLERS[vcs] = {}
65 65
        HANDLERS[vcs][method] = f
66 66
        return f
67 +
67 68
    return decorate
68 69
69 70
70 -
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
71 -
                env=None):
71 +
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
72 72
    """Call the given command(s)."""
73 73
    assert isinstance(commands, list)
74 74
    p = None
75 75
    for c in commands:
76 76
        try:
77 77
            dispcmd = str([c] + args)
78 78
            # remember shell=False, so use git.cmd on windows, not just git
79 -
            p = subprocess.Popen([c] + args, cwd=cwd, env=env,
80 -
                                 stdout=subprocess.PIPE,
81 -
                                 stderr=(subprocess.PIPE if hide_stderr
82 -
                                         else None))
79 +
            p = subprocess.Popen(
80 +
                [c] + args,
81 +
                cwd=cwd,
82 +
                env=env,
83 +
                stdout=subprocess.PIPE,
84 +
                stderr=(subprocess.PIPE if hide_stderr else None),
85 +
            )
83 86
            break
84 87
        except EnvironmentError:
85 88
            e = sys.exc_info()[1]
@@ -116,16 +119,22 @@
Loading
116 119
    for i in range(3):
117 120
        dirname = os.path.basename(root)
118 121
        if dirname.startswith(parentdir_prefix):
119 -
            return {"version": dirname[len(parentdir_prefix):],
120 -
                    "full-revisionid": None,
121 -
                    "dirty": False, "error": None, "date": None}
122 +
            return {
123 +
                "version": dirname[len(parentdir_prefix) :],
124 +
                "full-revisionid": None,
125 +
                "dirty": False,
126 +
                "error": None,
127 +
                "date": None,
128 +
            }
122 129
        else:
123 130
            rootdirs.append(root)
124 131
            root = os.path.dirname(root)  # up a level
125 132
126 133
    if verbose:
127 -
        print("Tried directories %s but none started with prefix %s" %
128 -
              (str(rootdirs), parentdir_prefix))
134 +
        print(
135 +
            "Tried directories %s but none started with prefix %s"
136 +
            % (str(rootdirs), parentdir_prefix)
137 +
        )
129 138
    raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
130 139
131 140
@@ -181,7 +190,7 @@
Loading
181 190
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
182 191
    # just "foo-1.0". If we see a "tag: " prefix, prefer those.
183 192
    TAG = "tag: "
184 -
    tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
193 +
    tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
185 194
    if not tags:
186 195
        # Either we're using git < 1.8.3, or there really are no tags. We use
187 196
        # a heuristic: assume all version tags have a digit. The old git %d
@@ -190,27 +199,34 @@
Loading
190 199
        # between branches and tags. By ignoring refnames without digits, we
191 200
        # filter out many common branch names like "release" and
192 201
        # "stabilization", as well as "HEAD" and "master".
193 -
        tags = set([r for r in refs if re.search(r'\d', r)])
202 +
        tags = set([r for r in refs if re.search(r"\d", r)])
194 203
        if verbose:
195 204
            print("discarding '%s', no digits" % ",".join(refs - tags))
196 205
    if verbose:
197 206
        print("likely tags: %s" % ",".join(sorted(tags)))
198 207
    for ref in sorted(tags):
199 208
        # sorting will prefer e.g. "2.0" over "2.0rc1"
200 209
        if ref.startswith(tag_prefix):
201 -
            r = ref[len(tag_prefix):]
210 +
            r = ref[len(tag_prefix) :]
202 211
            if verbose:
203 212
                print("picking %s" % r)
204 -
            return {"version": r,
205 -
                    "full-revisionid": keywords["full"].strip(),
206 -
                    "dirty": False, "error": None,
207 -
                    "date": date}
213 +
            return {
214 +
                "version": r,
215 +
                "full-revisionid": keywords["full"].strip(),
216 +
                "dirty": False,
217 +
                "error": None,
218 +
                "date": date,
219 +
            }
208 220
    # no suitable tags, so version is "0+unknown", but full hex is still there
209 221
    if verbose:
210 222
        print("no suitable tags, using unknown + full revision id")
211 -
    return {"version": "0+unknown",
212 -
            "full-revisionid": keywords["full"].strip(),
213 -
            "dirty": False, "error": "no suitable tags", "date": None}
223 +
    return {
224 +
        "version": "0+unknown",
225 +
        "full-revisionid": keywords["full"].strip(),
226 +
        "dirty": False,
227 +
        "error": "no suitable tags",
228 +
        "date": None,
229 +
    }
214 230
215 231
216 232
@register_vcs_handler("git", "pieces_from_vcs")
@@ -225,19 +241,27 @@
Loading
225 241
    if sys.platform == "win32":
226 242
        GITS = ["git.cmd", "git.exe"]
227 243
228 -
    out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
229 -
                          hide_stderr=True)
244 +
    out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
230 245
    if rc != 0:
231 246
        if verbose:
232 247
            print("Directory %s not under git control" % root)
233 248
        raise NotThisMethod("'git rev-parse --git-dir' returned error")
234 249
235 250
    # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
236 251
    # if there isn't one, this yields HEX[-dirty] (no NUM)
237 -
    describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
238 -
                                          "--always", "--long",
239 -
                                          "--match", "%s*" % tag_prefix],
240 -
                                   cwd=root)
252 +
    describe_out, rc = run_command(
253 +
        GITS,
254 +
        [
255 +
            "describe",
256 +
            "--tags",
257 +
            "--dirty",
258 +
            "--always",
259 +
            "--long",
260 +
            "--match",
261 +
            "%s*" % tag_prefix,
262 +
        ],
263 +
        cwd=root,
264 +
    )
241 265
    # --long was added in git-1.5.5
242 266
    if describe_out is None:
243 267
        raise NotThisMethod("'git describe' failed")
@@ -260,17 +284,16 @@
Loading
260 284
    dirty = git_describe.endswith("-dirty")
261 285
    pieces["dirty"] = dirty
262 286
    if dirty:
263 -
        git_describe = git_describe[:git_describe.rindex("-dirty")]
287 +
        git_describe = git_describe[: git_describe.rindex("-dirty")]
264 288
265 289
    # now we have TAG-NUM-gHEX or HEX
266 290
267 291
    if "-" in git_describe:
268 292
        # TAG-NUM-gHEX
269 -
        mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
293 +
        mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
270 294
        if not mo:
271 295
            # unparseable. Maybe git-describe is misbehaving?
272 -
            pieces["error"] = ("unable to parse git-describe output: '%s'"
273 -
                               % describe_out)
296 +
            pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
274 297
            return pieces
275 298
276 299
        # tag
@@ -279,10 +302,12 @@
Loading
279 302
            if verbose:
280 303
                fmt = "tag '%s' doesn't start with prefix '%s'"
281 304
                print(fmt % (full_tag, tag_prefix))
282 -
            pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
283 -
                               % (full_tag, tag_prefix))
305 +
            pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
306 +
                full_tag,
307 +
                tag_prefix,
308 +
            )
284 309
            return pieces
285 -
        pieces["closest-tag"] = full_tag[len(tag_prefix):]
310 +
        pieces["closest-tag"] = full_tag[len(tag_prefix) :]
286 311
287 312
        # distance: number of commits since tag
288 313
        pieces["distance"] = int(mo.group(2))
@@ -293,13 +318,13 @@
Loading
293 318
    else:
294 319
        # HEX: no tags
295 320
        pieces["closest-tag"] = None
296 -
        count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
297 -
                                    cwd=root)
321 +
        count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
298 322
        pieces["distance"] = int(count_out)  # total number of commits
299 323
300 324
    # commit date: see ISO-8601 comment in git_versions_from_keywords()
301 -
    date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
302 -
                       cwd=root)[0].strip()
325 +
    date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[
326 +
        0
327 +
    ].strip()
303 328
    pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
304 329
305 330
    return pieces
@@ -330,8 +355,7 @@
Loading
330 355
                rendered += ".dirty"
331 356
    else:
332 357
        # exception #1
333 -
        rendered = "0+untagged.%d.g%s" % (pieces["distance"],
334 -
                                          pieces["short"])
358 +
        rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
335 359
        if pieces["dirty"]:
336 360
            rendered += ".dirty"
337 361
    return rendered
@@ -445,11 +469,13 @@
Loading
445 469
def render(pieces, style):
446 470
    """Render the given version pieces into the requested style."""
447 471
    if pieces["error"]:
448 -
        return {"version": "unknown",
449 -
                "full-revisionid": pieces.get("long"),
450 -
                "dirty": None,
451 -
                "error": pieces["error"],
452 -
                "date": None}
472 +
        return {
473 +
            "version": "unknown",
474 +
            "full-revisionid": pieces.get("long"),
475 +
            "dirty": None,
476 +
            "error": pieces["error"],
477 +
            "date": None,
478 +
        }
453 479
454 480
    if not style or style == "default":
455 481
        style = "pep440"  # the default
@@ -469,9 +495,13 @@
Loading
469 495
    else:
470 496
        raise ValueError("unknown style '%s'" % style)
471 497
472 -
    return {"version": rendered, "full-revisionid": pieces["long"],
473 -
            "dirty": pieces["dirty"], "error": None,
474 -
            "date": pieces.get("date")}
498 +
    return {
499 +
        "version": rendered,
500 +
        "full-revisionid": pieces["long"],
501 +
        "dirty": pieces["dirty"],
502 +
        "error": None,
503 +
        "date": pieces.get("date"),
504 +
    }
475 505
476 506
477 507
def get_versions():
@@ -485,8 +515,7 @@
Loading
485 515
    verbose = cfg.verbose
486 516
487 517
    try:
488 -
        return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
489 -
                                          verbose)
518 +
        return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
490 519
    except NotThisMethod:
491 520
        pass
492 521
@@ -495,13 +524,16 @@
Loading
495 524
        # versionfile_source is the relative path from the top of the source
496 525
        # tree (where the .git directory might live) to this file. Invert
497 526
        # this to find the root from __file__.
498 -
        for i in cfg.versionfile_source.split('/'):
527 +
        for i in cfg.versionfile_source.split("/"):
499 528
            root = os.path.dirname(root)
500 529
    except NameError:
501 -
        return {"version": "0+unknown", "full-revisionid": None,
502 -
                "dirty": None,
503 -
                "error": "unable to find root of source tree",
504 -
                "date": None}
530 +
        return {
531 +
            "version": "0+unknown",
532 +
            "full-revisionid": None,
533 +
            "dirty": None,
534 +
            "error": "unable to find root of source tree",
535 +
            "date": None,
536 +
        }
505 537
506 538
    try:
507 539
        pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -515,6 +547,10 @@
Loading
515 547
    except NotThisMethod:
516 548
        pass
517 549
518 -
    return {"version": "0+unknown", "full-revisionid": None,
519 -
            "dirty": None,
520 -
            "error": "unable to compute version", "date": None}
550 +
    return {
551 +
        "version": "0+unknown",
552 +
        "full-revisionid": None,
553 +
        "dirty": None,
554 +
        "error": "unable to compute version",
555 +
        "date": None,
556 +
    }

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 3 files with coverage changes found.

Changes in paprika/simulate.py
+1
Loading file...
Changes in paprika/tests/test_restraints.py
+1
Loading file...
Changes in paprika/__init__.py
+1
Loading file...
Files Coverage
paprika -0.02% 77.20%
setup.py 16.08%
Project Totals (30 files) 74.02%
Loading