Skip to content

Commit

Permalink
Merge pull request #64 from Erastova-group/siminp_fixes
Browse files Browse the repository at this point in the history
Add updated core and UC files
  • Loading branch information
punkpony authored Jan 24, 2024
2 parents aa4740f + 97d882f commit 9f7aa54
Show file tree
Hide file tree
Showing 62 changed files with 3,096 additions and 5 deletions.
7 changes: 7 additions & 0 deletions package/ClayCode/core/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,13 @@ def __init__(self, path: Union[BasicPath, Dir], check=False, order=None):
# self._data.append(FileFactory(file, check=check))
self.data = self._data

def __repr__(self):
return (
f"{self.__class__.__name__}({self.path.name}: "
+ ", ".join([file.name for file in self.data])
+ ")"
)


class PathList(FileList):
pass
Expand Down
2 changes: 2 additions & 0 deletions package/ClayCode/core/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@
TABSIZE = 4

ANGSTROM = "\u212B"
GREATER_EQUAL = "\u2265"
LESS_EQUAL = "\u2264"
42 changes: 38 additions & 4 deletions package/ClayCode/core/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def run_analysis(instance: analysis_class, start: int, stop: int, step: int):
if v is not None:
kwarg_dict[k] = v
instance.run(**kwarg_dict)
return instance


@overload
Expand Down Expand Up @@ -217,44 +218,77 @@ def get_selections(infiles, sel, clay_type, other=None, in_memory=False):
u = MDAnalysis.Universe(*infiles, in_memory=in_memory)
# only resname specified
if len(sel) == 1:
sel_str = sel[0]
sel = u.select_atoms(f"resname {sel[0]}")

# rename and atom type specified
elif len(sel) == 2:
# expand search string for terminal O atom types
if sel[1] == "OT*":
sel[1] = "OT* O OXT"
sel_str = "{}: {}".format(*sel)
sel = u.select_atoms(f"resname {sel[0]}* and name {sel[1]}")

else:
raise ValueError('Expected 1 or 2 arguments for "sel"')

if other is None:
pass
elif len(other) == 1:
logger.debug(f"other: {other}")
other_str = other[0]
other = u.select_atoms(f"resname {other[0]}")

elif len(other) == 2:
logger.debug(f"other: {other}")
if other[1] == "OT*":
other[1] = "OT* O OXT"
other_str = "{}: {}".format(*other)
other = u.select_atoms(f"resname {other[0]}* and name {other[1]}")
else:
raise ValueError('Expected 1 or 2 arguments for "other"')
clay = u.select_atoms(f"resname {clay_type}* and name OB* o*")
logger.finfo(
f"'clay': Selected {clay.n_atoms} atoms of "
f"{clay.n_residues} {clay_type!r} unit cells"
# logger.finfo(
# f"'clay': Selected {clay.n_atoms} atoms of "
# f"{clay.n_residues} unit cells"
# )
log_atomgroup_info(
ag=clay, ag_name=clay_type, kwd_str="Clay unit cell type"
)

sel = select_outside_clay_stack(sel, clay)
# Clay + two other atom groups selected
log_atomgroup_info(ag=sel, ag_name=sel_str, kwd_str="Atom selection")

if other is not None:
other = select_outside_clay_stack(other, clay)
log_atomgroup_info(
ag=other, ag_name=other_str, kwd_str="Second atom selection"
)
return sel, clay, other

# Only clay + one other atom group selected
else:
return sel, clay


def get_ag_numbers_info(ag: AtomGroup) -> Tuple[int, int]:
return "Selected {} atoms in {} residues.".format(
ag.n_atoms, ag.n_residues
)


def log_atomgroup_info(ag: AtomGroup, kwd_str: str, ag_name: str):
if ag.n_atoms > 0:
logger.finfo(f"{ag_name!r}", kwd_str=f"{kwd_str}: ")
logger.finfo(get_ag_numbers_info(ag))
else:
logger.error(
f"{ag_name} contains 0 atoms. Check atom selection parameters."
)
sys.exit(1)


def select_clay(
universe: MDAnalysis.Universe,
ff: Optional[ForceField] = None,
Expand Down Expand Up @@ -568,7 +602,7 @@ def select_cyzone(
:rtype: NoReturn
"""
z_col = distances[:, :, 2]
z_col.mask = np.abs(distances[:, :, 2]) > z_dist
z_col.mask = np.abs(z_col) > z_dist
distances.mask = np.broadcast_to(
z_col.mask[:, :, np.newaxis], distances.shape
)
Expand Down
126 changes: 125 additions & 1 deletion package/ClayCode/core/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,127 @@
"analyse", help="Analyse clay simulations."
)

analysisparser.add_argument(
"-name", type=str, help="System name", dest="sysname", required=True
)
analysisparser.add_argument(
"-inp",
type=str,
help="Input file names",
nargs=2,
metavar=("coordinates", "trajectory"),
dest="infiles",
required=False,
)
analysisparser.add_argument(
"-inpname",
type=str,
help="Input file names",
metavar="name_stem",
dest="inpname",
required=False,
)
analysisparser.add_argument(
"-uc",
type=str,
help="Clay unit cell type",
dest="clay_type",
required=True,
)
analysisparser.add_argument(
"-sel",
type=str,
nargs="+",
help="Atom type selection",
dest="sel",
required=True,
)
analysisparser.add_argument(
"-n_bins",
default=None,
type=int,
help="Number of bins in histogram",
dest="n_bins",
)
analysisparser.add_argument(
"-bin_step",
type=float,
default=None,
help="bin size in histogram",
dest="bin_step",
)
analysisparser.add_argument(
"-xyrad",
type=float,
default=3,
help="xy-radius for calculating z-position clay surface",
dest="xyrad",
)
analysisparser.add_argument(
"-cutoff",
type=float,
default=20,
help="cutoff in z-direction",
dest="cutoff",
)

analysisparser.add_argument(
"-start",
type=int,
default=None,
help="First frame for analysis.",
dest="start",
)
analysisparser.add_argument(
"-step",
type=int,
default=None,
help="Frame steps for analysis.",
dest="step",
)
analysisparser.add_argument(
"-stop",
type=int,
default=None,
help="Last frame for analysis.",
dest="stop",
)
analysisparser.add_argument(
"-out",
type=str,
help="Filename for results pickle.",
dest="save",
default=True,
)
analysisparser.add_argument(
"-check_traj",
type=int,
default=False,
help="Expected trajectory length.",
dest="check_traj_len",
)
analysisparser.add_argument(
"--write_z",
type=str,
default=True,
help="Binary array output of selection z-distances.",
dest="write",
)
analysisparser.add_argument(
"--overwrite",
action="store_true",
default=False,
help="Overwrite existing z-distance array data.",
dest="overwrite",
)
analysisparser.add_argument(
"--update",
action="store_true",
default=False,
help="Overwrite existing trajectory and coordinate array data.",
dest="new",
)

# plot analysis results
plotparser = subparsers.add_parser(
"plot", help="Plot simulation analysis results"
Expand Down Expand Up @@ -309,6 +430,7 @@
dest="yaml_file",
)


# siminp_subparsers = siminpparser.add_subparsers()

# dspace_arg_group = siminpparser.add_argument_group("il_spacing")
Expand Down Expand Up @@ -703,7 +825,9 @@ def check(self) -> None:
)
if tbc_match:
pass
self.uc_stem = self._uc_path.itp_filelist[0].stem[:-3]
self.uc_stem = self._uc_path.itp_filelist.filter(
"[A-Z][A-Z0-9]\d\d\d"
)[0].stem[:-3]
logger.debug(f"Setting unit cell type: {self._uc_name!r}")
else:
raise ValueError(f"Unknown unit cell type {uc_type!r}!")
Expand Down
43 changes: 43 additions & 0 deletions package/ClayCode/data/data/UCS/D21/D2000.gro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
trans-vacant dioctahedral smectite, Garfield Nontronite, AMCSD: 0007180
40
1D200 HO1 1 0.183 0.000 0.583
1D200 HO2 2 0.447 0.457 0.583
1D200 HO3 3 0.158 0.000 0.377
1D200 HO4 4 0.422 0.457 0.377
1D200 OH1 5 0.084 0.000 0.583
1D200 OH2 6 0.348 0.457 0.583
1D200 OH3 7 0.257 0.000 0.377
1D200 OH4 8 -0.007 0.457 0.377
1D200 OB1 9 0.049 0.285 0.590
1D200 OB2 10 0.312 0.742 0.590
1D200 OB3 11 0.049 0.629 0.590
1D200 OB4 12 0.312 0.172 0.590
1D200 OB5 13 0.292 0.285 0.370
1D200 OB6 14 0.029 0.742 0.370
1D200 OB7 15 0.292 0.629 0.370
1D200 OB8 16 0.029 0.172 0.370
1D200 OB9 17 0.009 0.457 0.796
1D200 OB10 18 0.272 0.000 0.796
1D200 OB11 19 0.333 0.457 0.164
1D200 OB12 20 0.069 0.000 0.164
1D200 OB13 21 0.401 0.686 0.814
1D200 OB14 22 0.137 0.229 0.814
1D200 OB15 23 0.401 0.229 0.814
1D200 OB16 24 0.137 0.686 0.814
1D200 OB17 25 0.468 0.686 0.146
1D200 OB18 26 0.204 0.229 0.146
1D200 OB19 27 0.468 0.229 0.146
1D200 OB20 28 0.204 0.686 0.146
1D200 FEO1 29 0.171 0.152 0.480
1D200 FEO2 30 0.434 0.609 0.480
1D200 FEO3 31 0.171 0.762 0.480
1D200 FEO4 32 0.434 0.305 0.480
1D200 ST1 33 0.017 0.301 0.753
1D200 ST2 34 0.281 0.758 0.753
1D200 ST3 35 0.017 0.613 0.753
1D200 ST4 36 0.281 0.156 0.753
1D200 ST5 37 0.324 0.301 0.207
1D200 ST6 38 0.060 0.758 0.207
1D200 ST7 39 0.324 0.613 0.207
1D200 ST8 40 0.060 0.156 0.207
0.52770 0.91400 0.96003 0.00000 0.00000 0.00000 0.00000 -0.18661 0.00000
57 changes: 57 additions & 0 deletions package/ClayCode/data/data/UCS/D21/D2000.itp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;
;
[ moleculetype ]
; name nrexcl
D2000 1

[ atoms ]
; nr type resnr residue atom cgnr charge mass typeB chargeB massB
; residue 1 D2000rtp D2000q 0.0
1 ho 1 D2000 HO1 1 0.425 1.008
2 ho 1 D2000 HO2 2 0.425 1.008
3 ho 1 D2000 HO3 3 0.425 1.008
4 ho 1 D2000 HO4 4 0.425 1.008
5 oh 1 D2000 OH1 5 -0.95 16
6 oh 1 D2000 OH2 6 -0.95 16
7 oh 1 D2000 OH3 7 -0.95 16
8 oh 1 D2000 OH4 8 -0.95 16
9 ob 1 D2000 OB1 9 -1.05 16
10 ob 1 D2000 OB2 10 -1.05 16
11 ob 1 D2000 OB3 11 -1.05 16
12 ob 1 D2000 OB4 12 -1.05 16
13 ob 1 D2000 OB5 13 -1.05 16
14 ob 1 D2000 OB6 14 -1.05 16
15 ob 1 D2000 OB7 15 -1.05 16
16 ob 1 D2000 OB8 16 -1.05 16
17 ob 1 D2000 OB9 17 -1.05 16
18 ob 1 D2000 OB10 18 -1.05 16
19 ob 1 D2000 OB11 19 -1.05 16
20 ob 1 D2000 OB12 20 -1.05 16
21 ob 1 D2000 OB13 21 -1.05 16
22 ob 1 D2000 OB14 22 -1.05 16
23 ob 1 D2000 OB15 23 -1.05 16
24 ob 1 D2000 OB16 24 -1.05 16
25 ob 1 D2000 OB17 25 -1.05 16
26 ob 1 D2000 OB18 26 -1.05 16
27 ob 1 D2000 OB19 27 -1.05 16
28 ob 1 D2000 OB20 28 -1.05 16
29 feo 1 D2000 FEO1 29 1.575 55.845
30 feo 1 D2000 FEO2 30 1.575 55.845
31 feo 1 D2000 FEO3 31 1.575 55.845
32 feo 1 D2000 FEO4 32 1.575 55.845
33 st 1 D2000 ST1 33 2.1 28.09
34 st 1 D2000 ST2 34 2.1 28.09
35 st 1 D2000 ST3 35 2.1 28.09
36 st 1 D2000 ST4 36 2.1 28.09
37 st 1 D2000 ST5 37 2.1 28.09
38 st 1 D2000 ST6 38 2.1 28.09
39 st 1 D2000 ST7 39 2.1 28.09
40 st 1 D2000 ST8 40 2.1 28.09


[ bonds ]
; i j funct length force.c.
1 5 1 0.1 463532.808
2 6 1 0.1 463532.808
3 7 1 0.1 463532.808
4 8 1 0.1 463532.808
Loading

0 comments on commit 9f7aa54

Please sign in to comment.