Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pycgtool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Graham
pycgtool
Commits
f4d68c58
Commit
f4d68c58
authored
3 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
refactor: tidy PDB load checks
parent
149e92ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pycgtool/frame.py
+13
-11
13 additions, 11 deletions
pycgtool/frame.py
with
13 additions
and
11 deletions
pycgtool/frame.py
+
13
−
11
View file @
f4d68c58
...
@@ -34,18 +34,20 @@ class NonMatchingSystemError(ValueError):
...
@@ -34,18 +34,20 @@ class NonMatchingSystemError(ValueError):
super
(
NonMatchingSystemError
,
self
).
__init__
(
msg
)
super
(
NonMatchingSystemError
,
self
).
__init__
(
msg
)
def
try_
load_traj
(
filepath
:
PathLike
,
**
kwargs
)
->
mdtraj
.
Trajectory
:
def
load_traj
(
filepath
:
PathLike
,
**
kwargs
)
->
mdtraj
.
Trajectory
:
"""
Load a trajectory, if a PDB fails with zero box volume disable volume check and try again.
"""
"""
Load a trajectory, if a PDB fails with zero box volume disable volume check and try again.
"""
filepath
=
pathlib
.
Path
(
filepath
)
filepath
=
pathlib
.
Path
(
filepath
)
if
filepath
.
suffix
.
lower
()
==
'
.pdb
'
:
# PDBs have a couple of things that can go wrong - we handle these here...
kwargs
.
pop
(
'
top
'
,
None
)
# Can't specify a topology for `load_pdb`
try
:
try
:
return
mdtraj
.
load
(
str
(
filepath
),
**
kwargs
)
return
mdtraj
.
load
_pdb
(
str
(
filepath
),
**
kwargs
)
except
FloatingPointError
:
except
FloatingPointError
:
# PDB file loading checks density using the simulation box
# PDB file loading checks density using the simulation box
# This can fail if the box volume is zero
# This can fail if the box volume is zero
if
filepath
.
suffix
.
lower
()
==
'
.pdb
'
:
kwargs
.
pop
(
'
top
'
,
None
)
# Can't specify a topology for `load_pdb`
trajectory
=
mdtraj
.
load_pdb
(
str
(
filepath
),
no_boxchk
=
True
,
**
kwargs
)
trajectory
=
mdtraj
.
load_pdb
(
str
(
filepath
),
no_boxchk
=
True
,
**
kwargs
)
logger
.
warning
(
logger
.
warning
(
'
Unitcell has zero volume - periodic boundaries will not be accounted for.
'
'
Unitcell has zero volume - periodic boundaries will not be accounted for.
'
...
@@ -54,7 +56,7 @@ def try_load_traj(filepath: PathLike, **kwargs) -> mdtraj.Trajectory:
...
@@ -54,7 +56,7 @@ def try_load_traj(filepath: PathLike, **kwargs) -> mdtraj.Trajectory:
return
trajectory
return
trajectory
raise
return
mdtraj
.
load
(
str
(
filepath
),
**
kwargs
)
class
Frame
:
class
Frame
:
...
@@ -74,14 +76,14 @@ class Frame:
...
@@ -74,14 +76,14 @@ class Frame:
if
topology_file
is
not
None
:
if
topology_file
is
not
None
:
try
:
try
:
logging
.
info
(
'
Loading topology file
'
)
logging
.
info
(
'
Loading topology file
'
)
self
.
_trajectory
=
try_
load_traj
(
topology_file
)
self
.
_trajectory
=
load_traj
(
topology_file
)
self
.
_topology
=
self
.
_trajectory
.
topology
self
.
_topology
=
self
.
_trajectory
.
topology
logging
.
info
(
'
Finished loading topology file
'
)
logging
.
info
(
'
Finished loading topology file
'
)
if
trajectory_file
is
not
None
:
if
trajectory_file
is
not
None
:
try
:
try
:
logging
.
info
(
'
Loading trajectory file - this may take a while
'
)
logging
.
info
(
'
Loading trajectory file - this may take a while
'
)
self
.
_trajectory
=
try_
load_traj
(
trajectory_file
,
top
=
self
.
_topology
)
self
.
_trajectory
=
load_traj
(
trajectory_file
,
top
=
self
.
_topology
)
self
.
_trajectory
=
self
.
_slice_trajectory
(
frame_start
,
frame_end
)
self
.
_trajectory
=
self
.
_slice_trajectory
(
frame_start
,
frame_end
)
logging
.
info
(
logging
.
info
(
'
Finished loading trajectory file - loaded %d frames
'
,
'
Finished loading trajectory file - loaded %d frames
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment