Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release_23.1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Nov 29, 2023
2 parents 9319ee5 + e7b3a29 commit 7643cc1
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 20 deletions.
9 changes: 9 additions & 0 deletions lib/galaxy/config/sample/datatypes_conf.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,13 @@
<datatype extension="castep" type="galaxy.datatypes.text:Castep" display_in_upload="true"/>
<datatype extension="param" type="galaxy.datatypes.text:Param" display_in_upload="true"/>
<datatype extension="den_fmt" type="galaxy.datatypes.text:FormattedDensity" display_in_upload="true"/>
<!-- Larch types -->
<datatype extension="prj" type="galaxy.datatypes.larch:AthenaProject" display_in_upload="true" description="Athena project file."/>
<datatype extension="inp" type="galaxy.datatypes.larch:FEFFInput" display_in_upload="true" description="FEFF input file."/>
<datatype extension="sp" type="galaxy.datatypes.tabular:CSV" subclass="true" description="CSV representing selected FEFF paths."/>
<datatype extension="gds" type="galaxy.datatypes.tabular:CSV" subclass="true" description="CSV representing GDS parameters."/>
<datatype extension="feff" type="galaxy.datatypes.tabular:CSV" subclass="true" description="CSV representing summary of FEFF paths."/>
<datatype extension="feffit" type="galaxy.datatypes.data:Text" subclass="true" description="Report of Artemis FEFFIT."/>
<!-- ECOLOGY types -->
<datatype extension="bil" type="galaxy.datatypes.binary:Binary" mimetype="application/octet-stream" display_in_upload="true" subclass="true" description="ENVI file with band interleave by line (BIL) format"/>
<datatype extension="hdr" type="galaxy.datatypes.data:Text" mimetype="text/plain" display_in_upload="true" subclass="true" description="ENVI metadata header file"/>
Expand Down Expand Up @@ -1224,6 +1231,8 @@
<sniffer type="galaxy.datatypes.media:Mpg"/>
<sniffer type="galaxy.datatypes.speech:TextGrid" />
<sniffer type="galaxy.datatypes.speech:BPF" />
<sniffer type="galaxy.datatypes.larch:FEFFInput" />
<sniffer type="galaxy.datatypes.larch:AthenaProject" />
<sniffer type="galaxy.datatypes.text:Castep" />
<sniffer type="galaxy.datatypes.text:CTLresult"/>
<sniffer type="galaxy.datatypes.text:FormattedDensity" />
Expand Down
218 changes: 218 additions & 0 deletions lib/galaxy/datatypes/larch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
from typing import List

from galaxy.datatypes.data import (
get_file_peek,
Text,
)
from galaxy.datatypes.metadata import MetadataElement
from galaxy.datatypes.protocols import DatasetProtocol
from galaxy.datatypes.sniff import (
build_sniff_from_prefix,
FilePrefix,
get_headers,
)


@build_sniff_from_prefix
class AthenaProject(Text):
"""
Athena project format
"""

file_ext = "prj"
compressed = True
compressed_format = "gzip"

MetadataElement(
name="atsym",
desc="Atom symbol",
readonly=True,
visible=True,
)
MetadataElement(
name="bkg_e0",
desc="Edge energy (eV)",
readonly=True,
visible=True,
)
MetadataElement(
name="edge",
desc="Edge",
readonly=True,
visible=True,
)
MetadataElement(
name="npts",
desc="Number of points",
readonly=True,
visible=True,
)
MetadataElement(
name="xmax",
desc="Maximum energy (eV)",
readonly=True,
visible=True,
)
MetadataElement(
name="xmin",
desc="Minimum energy (eV)",
readonly=True,
visible=True,
)

def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
"""
Try to guess if the file is an Athena project file.
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('test.prj')
>>> AthenaProject().sniff(fname)
True
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('Si.cif')
>>> AthenaProject().sniff(fname)
False
"""

return file_prefix.startswith("# Athena project file")

def set_meta(self, dataset: DatasetProtocol, *, overwrite: bool = True, **kwd) -> None:
"""
Extract metadata from @args
"""

def extract_arg(args: List[str], arg_name: str):
try:
index = args.index(f"'{arg_name}'")
setattr(dataset.metadata, arg_name, args[index + 1].replace("'", ""))
except ValueError:
return

headers = get_headers(dataset.file_name, sep=" = ", count=3, comment_designator="#")
args = []
for header in headers:
if header[0] == "@args":
args = header[1][1:-2].split(",")
break

extract_arg(args, "atsym")
extract_arg(args, "bkg_e0")
extract_arg(args, "edge")
extract_arg(args, "npts")
extract_arg(args, "xmax")
extract_arg(args, "xmin")

def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
if not dataset.dataset.purged:
dataset.peek = get_file_peek(dataset.file_name)
dataset.info = (
f"atsym: {dataset.metadata.atsym}\n"
f"bkg_e0: {dataset.metadata.bkg_e0}\n"
f"edge: {dataset.metadata.edge}\n"
f"npts: {dataset.metadata.npts}\n"
f"xmax: {dataset.metadata.xmax}\n"
f"xmin: {dataset.metadata.xmin}"
)
dataset.blurb = f"Athena project file of {dataset.metadata.atsym} {dataset.metadata.edge} edge"

else:
dataset.peek = "file does not exist"
dataset.blurb = "file purged from disk"


@build_sniff_from_prefix
class FEFFInput(Text):
"""
FEFF input format
"""

file_ext = "inp"

MetadataElement(
name="title_block",
desc="Title block",
readonly=True,
visible=True,
)

def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
"""
Try to guess if the file is an FEFF input file.
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('larch_pymatgen.inp')
>>> FEFFInput().sniff(fname)
True
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('larch_atoms.inp')
>>> FEFFInput().sniff(fname)
True
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('larch_potentials.inp')
>>> FEFFInput().sniff(fname)
True
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('larch_bad_atoms.txt')
>>> FEFFInput().sniff(fname)
False
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('larch_bad_potentials.txt')
>>> FEFFInput().sniff(fname)
False
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('Si.cif')
>>> FEFFInput().sniff(fname)
False
"""
# pymatgen marks generated FEFF inputs, but user might also upload from another source
if file_prefix.startswith("* This FEFF.inp file generated by pymatgen"):
return True

generator = file_prefix.line_iterator()
try:
line = next(generator).strip()
while line is not None:
if line == "POTENTIALS":
line = next(generator).strip()
if line[0] == "*":
words = line[1:].split()
if (words[0] in ["potential-index", "ipot"]) and (words[1] == "Z"):
return True
return False

elif line == "ATOMS":
line = next(generator).strip()
if line[0] == "*":
words = line[1:].split()
if words[:4] == ["x", "y", "z", "ipot"]:
return True
return False

else:
line = next(generator).strip()

except StopIteration:
return False

return False

def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> None:
"""
Extract metadata from TITLE
"""
title_block = ""
headers = get_headers(dataset.file_name, sep=None, comment_designator="*")
for header in headers:
if header and header[0] == "TITLE":
title_block += " ".join(header[1:]) + "\n"

dataset.metadata.title_block = title_block

def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
if not dataset.dataset.purged:
dataset.peek = get_file_peek(dataset.file_name)
dataset.info = dataset.metadata.title_block

else:
dataset.peek = "file does not exist"
dataset.blurb = "file purged from disk"
44 changes: 44 additions & 0 deletions lib/galaxy/datatypes/test/larch_atoms.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
TITLE comment: None given
TITLE Source:
TITLE Structure Summary: Fe2 S4
TITLE Reduced formula: FeS2
TITLE space group: (Pnnm), space number: (58)
TITLE abc: 3.385200 4.447400 5.428700
TITLE angles: 90.000000 90.000000 90.000000
TITLE sites: 6
* 1 Fe 0.000000 0.000000 0.000000
* 2 Fe 0.500000 0.500000 0.500000
* 3 S 0.000000 0.199900 0.378040
* 4 S 0.000000 0.800100 0.621960
* 5 S 0.500000 0.699900 0.121960
* 6 S 0.500000 0.300100 0.878040

ATOMS
* x y z ipot Atom Distance Number
**********- ********- ******- ****** ****** ********** ********
0 0 0 0 Fe 0 0
-0.889035 -2.05227 -0 2 S 2.23656 4
0.889035 2.05227 0 2 S 2.23656 22
-1.33466 0.662084 -1.6926 2 S 2.2549 6
-1.33466 0.662084 1.6926 2 S 2.2549 8
1.33466 -0.662084 -1.6926 2 S 2.2549 11
1.33466 -0.662084 1.6926 2 S 2.2549 13
0 0 -3.3852 1 Fe 3.3852 18
0 0 3.3852 1 Fe 3.3852 19
-0.889035 3.37643 0 2 S 3.49152 9
0.889035 -3.37643 -0 2 S 3.49152 15
-3.11273 -0.662084 -1.6926 2 S 3.60449 1
-3.11273 -0.662084 1.6926 2 S 3.60449 3
3.11273 0.662084 -1.6926 2 S 3.60449 16
3.11273 0.662084 1.6926 2 S 3.60449 20
-2.2237 -2.71435 -1.6926 1 Fe 3.89582 2
-2.2237 -2.71435 1.6926 1 Fe 3.89582 5
-2.2237 2.71435 -1.6926 1 Fe 3.89582 7
-2.2237 2.71435 1.6926 1 Fe 3.89582 10
2.2237 -2.71435 -1.6926 1 Fe 3.89582 12
2.2237 -2.71435 1.6926 1 Fe 3.89582 14
2.2237 2.71435 -1.6926 1 Fe 3.89582 17
2.2237 2.71435 1.6926 1 Fe 3.89582 21
END


44 changes: 44 additions & 0 deletions lib/galaxy/datatypes/test/larch_bad_atoms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
TITLE comment: None given
TITLE Source:
TITLE Structure Summary: Fe2 S4
TITLE Reduced formula: FeS2
TITLE space group: (Pnnm), space number: (58)
TITLE abc: 3.385200 4.447400 5.428700
TITLE angles: 90.000000 90.000000 90.000000
TITLE sites: 6
* 1 Fe 0.000000 0.000000 0.000000
* 2 Fe 0.500000 0.500000 0.500000
* 3 S 0.000000 0.199900 0.378040
* 4 S 0.000000 0.800100 0.621960
* 5 S 0.500000 0.699900 0.121960
* 6 S 0.500000 0.300100 0.878040

ATOMS
* a b c ipot Atom Distance Number
**********- ********- ******- ****** ****** ********** ********
0 0 0 0 Fe 0 0
-0.889035 -2.05227 -0 2 S 2.23656 4
0.889035 2.05227 0 2 S 2.23656 22
-1.33466 0.662084 -1.6926 2 S 2.2549 6
-1.33466 0.662084 1.6926 2 S 2.2549 8
1.33466 -0.662084 -1.6926 2 S 2.2549 11
1.33466 -0.662084 1.6926 2 S 2.2549 13
0 0 -3.3852 1 Fe 3.3852 18
0 0 3.3852 1 Fe 3.3852 19
-0.889035 3.37643 0 2 S 3.49152 9
0.889035 -3.37643 -0 2 S 3.49152 15
-3.11273 -0.662084 -1.6926 2 S 3.60449 1
-3.11273 -0.662084 1.6926 2 S 3.60449 3
3.11273 0.662084 -1.6926 2 S 3.60449 16
3.11273 0.662084 1.6926 2 S 3.60449 20
-2.2237 -2.71435 -1.6926 1 Fe 3.89582 2
-2.2237 -2.71435 1.6926 1 Fe 3.89582 5
-2.2237 2.71435 -1.6926 1 Fe 3.89582 7
-2.2237 2.71435 1.6926 1 Fe 3.89582 10
2.2237 -2.71435 -1.6926 1 Fe 3.89582 12
2.2237 -2.71435 1.6926 1 Fe 3.89582 14
2.2237 2.71435 -1.6926 1 Fe 3.89582 17
2.2237 2.71435 1.6926 1 Fe 3.89582 21
END


24 changes: 24 additions & 0 deletions lib/galaxy/datatypes/test/larch_bad_potentials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
TITLE comment: None given
TITLE Source:
TITLE Structure Summary: Fe2 S4
TITLE Reduced formula: FeS2
TITLE space group: (Pnnm), space number: (58)
TITLE abc: 3.385200 4.447400 5.428700
TITLE angles: 90.000000 90.000000 90.000000
TITLE sites: 6
* 1 Fe 0.000000 0.000000 0.000000
* 2 Fe 0.500000 0.500000 0.500000
* 3 S 0.000000 0.199900 0.378040
* 4 S 0.000000 0.800100 0.621960
* 5 S 0.500000 0.699900 0.121960
* 6 S 0.500000 0.300100 0.878040

POTENTIALS
* pot Z tag lmax1 lmax2 xnatph(stoichometry) spinph
******- **- ****- ******- ******- ********************** ********
0 26 Fe -1 -1 0.0001 0
1 26 Fe -1 -1 2 0
2 16 S -1 -1 4 0
END


24 changes: 24 additions & 0 deletions lib/galaxy/datatypes/test/larch_potentials.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
TITLE comment: None given
TITLE Source:
TITLE Structure Summary: Fe2 S4
TITLE Reduced formula: FeS2
TITLE space group: (Pnnm), space number: (58)
TITLE abc: 3.385200 4.447400 5.428700
TITLE angles: 90.000000 90.000000 90.000000
TITLE sites: 6
* 1 Fe 0.000000 0.000000 0.000000
* 2 Fe 0.500000 0.500000 0.500000
* 3 S 0.000000 0.199900 0.378040
* 4 S 0.000000 0.800100 0.621960
* 5 S 0.500000 0.699900 0.121960
* 6 S 0.500000 0.300100 0.878040

POTENTIALS
*ipot Z tag lmax1 lmax2 xnatph(stoichometry) spinph
******- **- ****- ******- ******- ********************** ********
0 26 Fe -1 -1 0.0001 0
1 26 Fe -1 -1 2 0
2 16 S -1 -1 4 0
END


Loading

0 comments on commit 7643cc1

Please sign in to comment.