Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into joss-paper
Browse files Browse the repository at this point in the history
  • Loading branch information
samwaseda committed Nov 3, 2023
2 parents 3bcb860 + 08ec3d4 commit 5af6fd6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ This code allows you to launch Metropolis Monte Carlo simulations via Heisenberg

## How to compile

Download all files and run `python setup.py build_ext --inplace`.
`mamonca` can be installed directly from conda:

```
conda install -c conda-forge mamonca
```
In order to use build it from the repository, run
```
git clone https://github.com/samwaseda/mamonca
cd mamonca
python setup.py build_ext --user
```

## First steps:

In the following simple (but complete) example, we create a bcc Fe system using [pyiron](http://github.com/pyiron/pyiron) and launch a Metropolis Monte Carlo simulation with a Heisenberg coefficient `J=0.1` (eV) for the first nearest neighbor pairs:

```python
from pyiron import Project
from mc import MC
from pyiron_atomistics import Project
from mamonca import MC

structure = Project('.').create.structure.bulk(
name='Fe',
Expand Down
47 changes: 47 additions & 0 deletions tests/test_full_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from mamonca import MC
import numpy as np
import unittest
import os


class TestTemplate(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
cls.ij = np.loadtxt(
os.path.join(cls.file_location, "neighbors.txt")
).astype(int)
cls.n = np.max(cls.ij) + 1


class TestRaw(TestTemplate):

def test_thermodynamic_integration(self):
mc = MC(self.n)
mc.set_heisenberg_coeff(0.1, *self.ij, index=0)
mc.set_heisenberg_coeff(-0.03, *self.ij, index=1)
mc.set_lambda(0.5)
mc.run(temperature=300, number_of_iterations=100)
self.assertLess(mc.get_energy(index=0), mc.get_energy(index=1))

class TestPredefine(TestTemplate):
def setUp(self):
self.mc = MC(self.n)
self.mc.set_heisenberg_coeff(0.1, *self.ij, index=0)

def test_metadynamics(self):
self.mc.set_metadynamics(max_range=1)
self.mc.run(temperature=300, number_of_iterations=100)
meta = self.mc.get_metadynamics_free_energy()
self.assertAlmostEqual(np.diff(meta["magnetization"]).ptp(), 0)
self.assertLessEqual(meta["free_energy"].max(), 0)

def test_spin_dynamics(self):
self.mc.switch_spin_dynamics()
self.mc.run(temperature=300, number_of_iterations=100)
self.assertLess(self.mc.get_energy(), 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5af6fd6

Please sign in to comment.