Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
578e25f9
Commit
578e25f9
authored
Sep 30, 2013
by
peastman
Browse files
Merge pull request #153 from rmcgibbo/element
add getByAtomicNumber to element.
parents
82cab8dd
7a44101f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
wrappers/python/simtk/openmm/app/element.py
wrappers/python/simtk/openmm/app/element.py
+15
-0
No files found.
wrappers/python/simtk/openmm/app/element.py
View file @
578e25f9
...
@@ -44,6 +44,7 @@ class Element:
...
@@ -44,6 +44,7 @@ class Element:
look up the Element with a particular chemical symbol."""
look up the Element with a particular chemical symbol."""
_elements_by_symbol
=
{}
_elements_by_symbol
=
{}
_elements_by_atomic_number
=
{}
def
__init__
(
self
,
number
,
name
,
symbol
,
mass
):
def
__init__
(
self
,
number
,
name
,
symbol
,
mass
):
## The atomic number of the element
## The atomic number of the element
...
@@ -58,6 +59,16 @@ class Element:
...
@@ -58,6 +59,16 @@ class Element:
s
=
symbol
.
strip
().
upper
()
s
=
symbol
.
strip
().
upper
()
assert
s
not
in
Element
.
_elements_by_symbol
assert
s
not
in
Element
.
_elements_by_symbol
Element
.
_elements_by_symbol
[
s
]
=
self
Element
.
_elements_by_symbol
[
s
]
=
self
if
number
in
Element
.
_elements_by_atomic_number
:
other_element
=
Element
.
_elements_by_atomic_number
[
number
]
if
mass
<
other_element
.
mass
:
# If two "elements" share the same atomic number, they're
# probably hydrogen and deuterium, and we want to choose
# the lighter one to put in the table by atomic_number,
# since it's the "canonical" element.
Element
.
_elements_by_atomic_number
[
number
]
=
self
else
:
Element
.
_elements_by_atomic_number
[
number
]
=
self
@
staticmethod
@
staticmethod
def
getBySymbol
(
symbol
):
def
getBySymbol
(
symbol
):
...
@@ -65,6 +76,10 @@ class Element:
...
@@ -65,6 +76,10 @@ class Element:
s
=
symbol
.
strip
().
upper
()
s
=
symbol
.
strip
().
upper
()
return
Element
.
_elements_by_symbol
[
s
]
return
Element
.
_elements_by_symbol
[
s
]
@
staticmethod
def
getByAtomicNumber
(
atomic_number
):
return
Element
.
_elements_by_atomic_number
[
atomic_number
]
# This is for backward compatibility.
# This is for backward compatibility.
def
get_by_symbol
(
symbol
):
def
get_by_symbol
(
symbol
):
s
=
symbol
.
strip
().
upper
()
s
=
symbol
.
strip
().
upper
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment