Skip to content

Commit

Permalink
Correctd setup.py and added requirements.txt. New logic for mago_add …
Browse files Browse the repository at this point in the history
…and now I/O functions return True on succees.
  • Loading branch information
bonfus committed May 27, 2017
1 parent 6bafa67 commit 8f39e27
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 48 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include MANIFEST.in
include LICENSE README.md
include requirements.txt
include muesr/core/spacegroup.dat
recursive-include muesr/tests/structures *
recursive-include docs *
Expand Down
3 changes: 2 additions & 1 deletion docs/Install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ and to activate the environment (linux and OsX) ::
cd muesr-env
source bin/activate
now you can install Muesr in the virtualenv with the command ::
now you can install LFC and Muesr in the virtualenv with the commands ::

pip install https://github.com/bonfus/muLFC/archive/master.tar.gz
pip install https://github.com/bonfus/muesr/archive/master.tar.gz
this will only provide the minimal dependencies. To have access to all
Expand Down
24 changes: 11 additions & 13 deletions muesr/i_o/sampleIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@



def save_sample(sample, filename="", fileobj=None):
def save_sample(sample, filename="", fileobj=None, overwrite=False):
"""
This function saves the sample provided in YAML format.
:param sample: the sample object
:param str filename: the filename used to store data.
:param file fileobj: a file object used in place of filename.
:param overwrite bool: if selected file should be overwritten.
:return: None
:rtype: None
:raises: TypeError
:raises: TypeError, ValueError, IsADirectoryError
"""


Expand Down Expand Up @@ -112,18 +113,18 @@ def save_sample(sample, filename="", fileobj=None):
if filename == "":
raise ValueError("Specify filename or provide a file object")

while os.path.isfile(filename):
if not ninput('Do you really want to overwite ' +
os.path.basename(filename) + '?', parse_bool):
filename = ninput('New file name: ')
else:
break
if os.path.isfile(filename) and (not overwrite):
warnings.warn('File not (over)written.', RuntimeWarning)
return False


# TODO: check overwrite and handle errors
with open(filename,'w') as f:
f.write(output)
return True

else:
fileobj.write(output)
return True


def load_sample(filename="", fileobj=None):
Expand All @@ -136,10 +137,7 @@ def load_sample(filename="", fileobj=None):
supersede the filename input.
:return: a sample object
:rtype: :py:class:`~Sample` object or None
:raises: ValueError
.. note::
Overwrite is not checked!
:raises: ValueError, FileNotFoundError, IsADirectoryError
"""

Expand Down
55 changes: 34 additions & 21 deletions muesr/utilities/ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



def mago_set_k(sample, kvalue=None,mm=None):
def mago_set_k(sample, kvalue=None, mm=None):

"""
Set propagation with respect to the conventional reciprocal cell
Expand All @@ -36,7 +36,7 @@ def mago_set_k(sample, kvalue=None,mm=None):
if not kvalue is None:
if isinstance(kvalue, np.ndarray) and ( kvalue.shape == (3,)):
smm.k = kvalue
return
return True
else:
try:
if kvalue is None:
Expand All @@ -46,37 +46,48 @@ def mago_set_k(sample, kvalue=None,mm=None):

except EOFError:
nprint("Ok.")
return
return False
except TypeError:
nprint("Cannot parse position.",'warn')
return
smm.k=np.array(kval,dtype=np.float)
return
return True


def mago_add(sample, coordinates='b-c'):
def mago_add(sample, coordinates='b-c', fcs=None, kvalue=None):
"""
Add a magnetic model (fourier components and K vector).
Adds a magnetic model (fourier components and K vector).
The order is automatically selected if succesfully added.
:param sample: A sample object.
:param string coordinates: coordinates of Fourier components
:param np.complex fcs: Fourier components in coordinate system
(default: Bohr magnetoc/ Cartesian coordinates)
:param np.ndarray kvalue: Propagation vector in r.l.u.
:returns: True if successful, False otherwise.
:rtype: bool
returns: None
"""

nmm = MM(sample.cell.get_number_of_atoms(),sample.cell.get_cell())

mago_set_k(sample, mm=nmm)
mago_set_FC(sample, mm=nmm, inputConvention=coordinates)
ret = mago_set_k(sample, mm=nmm, kvalue=kvalue)
if not ret:
return False

ret = mago_set_FC(sample, mm=nmm, inputConvention=coordinates, fcs=fcs)
if not ret:
return False

sample.mm = nmm

return True



def mago_set_FC(sample, fcs= None, atoms_types = None, mm=None, inputConvention='b-c'):
def mago_set_FC(sample, fcs = None, atoms_types = None, mm=None, inputConvention='b-c'):
"""
defines fourier components for the unit cell.
Values are given in CARTESIAN coordinates (this is different from mcif convention)
Defines fourier components for the unit cell.
"""


Expand All @@ -93,27 +104,27 @@ def mago_set_FC(sample, fcs= None, atoms_types = None, mm=None, inputConvention=
inputConvEnum = -1

if inputConvention.lower() in ['bohr-cartesian', 'b-c']:
nprint('Magnetic moments in bohr magnetons and cartesian coordinates.')
nprint('Magnetic moments in Bohr magnetons and cartesian coordinates.')
inputConvEnum = 0

elif inputConvention.lower() in ['bohr/angstrom-lattice', 'b/a-l']:
nprint('Magnetic moments in bohr magnetons/angstrom and lattice coordinates.')
nprint('Magnetic moments in Bohr magnetons/angstrom and lattice coordinates.')
inputConvEnum = 1

elif inputConvention.lower() in ['bohr-lattice','b-l']:
nprint('Magnetic moments in bohr magnetons and lattice coordinates.')
nprint('Magnetic moments in Bohr magnetons and lattice coordinates.')
inputConvEnum = 2

else:
nprint('Invalid Fourier Description method: ' + inputConvention.lower() ,'error')
return
nprint('Invalid Fourier Description method: ' + inputConvention.lower() ,'error.')
return False




if not fcs is None:
smm.fc_set(fcs, inputConvEnum)
return
return True



Expand All @@ -122,7 +133,7 @@ def mago_set_FC(sample, fcs= None, atoms_types = None, mm=None, inputConvention=


if atoms_types is None:
atoms_types=ninput('Which atom? (enter for all)').split()
atoms_types=ninput('Which atom? (enter for all): ').split()

if atoms_types == []:
set_this_fc = lambda x: True
Expand Down Expand Up @@ -154,8 +165,10 @@ def mago_set_FC(sample, fcs= None, atoms_types = None, mm=None, inputConvention=

if gotEOS:
nprint('Nothing set')
return False
else:
smm.fc_set(fcs, inputConvEnum)
return True



16 changes: 9 additions & 7 deletions muesr/utilities/muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ def muon_set_frac(sample, arg = None):

except EOFError:
nprint("Ok.")
return
return False
except TypeError:
nprint("Cannot parse position.",'warn')
return
return False

if (not isinstance(arg, np.ndarray)):
pos = np.array(pos)

sample.add_muon(pos)
return
return True
else:
nprintmsg('NS')
#nprintmsg('NS')
return False



Expand All @@ -57,11 +58,12 @@ def muon_find_equiv(sample, eps=1.e-3):
sample._reset(muon=True)
for p in eqpoints:
sample.add_muon(np.array(p))

return True

def muon_reset(sample):
"""
Resets muon position.
returns: None
Removes all previously set muon positions.
returns: True
"""
sample._reset(muon=True)
return True
2 changes: 1 addition & 1 deletion muesr/utilities/printer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from muesr.core.nprint import print_cell as pc




def print_cell(sample):
"""
Print base cell
"""
if sample._check_lattice():
pc(sample._cell)
return True



Expand Down
8 changes: 5 additions & 3 deletions muesr/utilities/xcrysden.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def show_structure(sample, supercell=[1,1,1], askConfirm=True, block=True):

if ans:
save_xsf(sample, os.path.join(config.XCrysTmp,'preview.xsf'),supercell=supercell)
run_xcrysden(os.path.join(config.XCrysTmp,'preview.xsf'),block)
return run_xcrysden(os.path.join(config.XCrysTmp,'preview.xsf'),block)
else:
return ans

def run_xcrysden(fname, block=True):
if config.XCrysExec == None:
warnings.warn("XCrysDen executable not found. Check configs.")
return
return False


spargs = dict(
Expand All @@ -66,4 +68,4 @@ def run_xcrysden(fname, block=True):

if block:
out, err = p.communicate()

return True
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
####### muesr-requirements.txt #######
#
###### C Extension ######
https://github.com/bonfus/muLFC/archive/master.tar.gz
#
###### Requirements for complete functionality ######
# See https://www.python.org/dev/peps/pep-0440/#version-specifiers
spglib >= 1.9
pyyaml >= 3.0

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
],
include_package_data=True,
package_dir={'muesr': 'muesr' },
requires=['numpy', 'LFC',],
install_requires=[
'numpy',
'numpy >= 1.6',
],
test_suite="muesr.tests",
)

0 comments on commit 8f39e27

Please sign in to comment.