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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Graham
pycgtool
Commits
19b40540
Verified
Commit
19b40540
authored
3 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
fix: backup forcefield directories instead of overwrite
parent
a9fdae85
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pycgtool/forcefield.py
+2
-1
2 additions, 1 deletion
pycgtool/forcefield.py
tests/test_forcefield.py
+14
-8
14 additions, 8 deletions
tests/test_forcefield.py
with
16 additions
and
9 deletions
pycgtool/forcefield.py
+
2
−
1
View file @
19b40540
...
@@ -8,7 +8,7 @@ import shutil
...
@@ -8,7 +8,7 @@ import shutil
import
typing
import
typing
from
.parsers
import
CFG
from
.parsers
import
CFG
from
.util
import
any_starts_with
,
file_write_lines
from
.util
import
any_starts_with
,
backup_file
,
file_write_lines
PathLike
=
typing
.
Union
[
pathlib
.
Path
,
str
]
PathLike
=
typing
.
Union
[
pathlib
.
Path
,
str
]
...
@@ -32,6 +32,7 @@ class ForceField:
...
@@ -32,6 +32,7 @@ class ForceField:
:param str name: Forcefield name to open/create
:param str name: Forcefield name to open/create
"""
"""
self
.
directory
=
pathlib
.
Path
(
dir_path
).
joinpath
(
f
'
ff
{
name
}
.ff
'
)
self
.
directory
=
pathlib
.
Path
(
dir_path
).
joinpath
(
f
'
ff
{
name
}
.ff
'
)
backup_file
(
self
.
directory
)
self
.
directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
self
.
directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
with
open
(
self
.
directory
.
joinpath
(
'
forcefield.itp
'
),
'
w
'
)
as
itp
:
with
open
(
self
.
directory
.
joinpath
(
'
forcefield.itp
'
),
'
w
'
)
as
itp
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_forcefield.py
+
14
−
8
View file @
19b40540
import
unittest
import
os
import
collections
import
collections
import
pathlib
import
tempfile
import
unittest
from
pycgtool.forcefield
import
ForceField
from
pycgtool.forcefield
import
ForceField
...
@@ -57,13 +58,18 @@ class ForceFieldTest(unittest.TestCase):
...
@@ -57,13 +58,18 @@ class ForceFieldTest(unittest.TestCase):
self
.
bondset
=
DummyBondSet
(
self
.
bonds
,
"
Dummy
"
)
self
.
bondset
=
DummyBondSet
(
self
.
bonds
,
"
Dummy
"
)
def
test_create
(
self
):
def
test_create
(
self
):
name
=
"
test
"
with
tempfile
.
TemporaryDirectory
()
as
t
:
dirname
=
"
fftest.ff
"
tmp_dir
=
pathlib
.
Path
(
t
)
name
=
"
test
"
ff_dir
=
tmp_dir
.
joinpath
(
'
fftest.ff
'
)
ForceField
(
name
,
dir_path
=
tmp_dir
)
self
.
assertTrue
(
ff_dir
.
exists
())
self
.
assertTrue
(
ff_dir
.
is_dir
())
ForceField
(
name
)
# Makes a backup of the existing ff and replaces it
self
.
assertTrue
(
os
.
path
.
exists
(
dirname
))
ForceField
(
name
,
dir_path
=
tmp_dir
)
self
.
assertTrue
(
os
.
path
.
isdir
(
dirname
))
ForceField
(
name
)
def
test_bond_section
(
self
):
def
test_bond_section
(
self
):
expected
=
[
expected
=
[
...
...
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