Skip to content

Commit 70c9564

Browse files
committed
fixes, automatic creation of strengths, Solenoid support
1 parent 6645d94 commit 70c9564

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,18 @@ plt.show()
7474
```python
7575
lhcModel.strengths
7676
```
77+
Set strengths:
7778
```python
7879
lhcModel.strengths['on_x1'] = 140
7980
lhcModel.strengths['on_x5'] = 140
8081
print(lhcModel.strengths['on_x5'])
8182
```
83+
Note that a new strength is automatically created if you assign it a value;
84+
a warning is issued in this case:
85+
```python
86+
lhcModel.strengths['on_xx5_v'] = 140
87+
```
88+
```INFO:root:Creating new MAD-X strength on_xx5_v```
8289
(jupyter/ipython autocompletion hints supported)
8390

8491
### Deal with Elements:

pyjmad/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.10"
1+
__version__ = "0.0.11"
22

33
__cmmnbuild_deps__ = [
44
"jmad-core-pro",
@@ -13,10 +13,10 @@
1313
]
1414

1515
__gradle_deps__ = [
16-
"jmad:jmad-core:0.2.2+",
16+
"jmad:jmad-core:0.2.3+",
1717
'jmad:jmad-modelpack-service:0.2.7+',
1818
'jmad:jmad-modelpack-fx:0.2.5+',
19-
"jmad:jmad-gui:0.3.24+",
19+
"jmad:jmad-gui:0.3.25+",
2020
"org.slf4j:slf4j-api:+",
2121
"org.slf4j:slf4j-log4j12:+",
2222
"log4j:log4j:1.2.17",

pyjmad/element.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def _specific_element(name, attributes):
6565
Quadrupole = _specific_element('Quadrupole', ['k1', 'tilt'])
6666
Sextupole = _specific_element('Sextupole', ['k2', 'tilt'])
6767
Octupole = _specific_element('Octupole', ['k3', 'tilt'])
68+
Solenoid = _specific_element('Solenoid', ['ks', 'ksi'])
6869

6970

7071
def from_jmad(jmadElement):
@@ -77,6 +78,7 @@ def from_jmad(jmadElement):
7778
'Octupole': Octupole,
7879
'Quadrupole': Quadrupole,
7980
'Sextupole': Sextupole,
81+
'Solenoid': Solenoid,
8082
'UnknownElement': Element
8183
}
8284
return _jmadElementMap[jmadElement.getClass().getSimpleName()](jmadElement)

pyjmad/modelpack.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ def _repo_from_uri(uri):
3434
raise ValueError('invalid repository URI: ' + uri)
3535

3636

37-
jmad_default_repositories = {}
38-
try:
39-
_JMadModelRepositories = org.jmad.modelpack.domain.JMadModelRepositories
40-
for method in _JMadModelRepositories.__javaclass__.getDeclaredMethods():
41-
if method.getModifiers() & java.lang.reflect.Modifier.PUBLIC:
42-
repo = method.getName()
43-
jmad_default_repositories[repo] = _repo_to_uri(getattr(_JMadModelRepositories, repo)())
44-
except Exception:
45-
logging.exception('can not fetch default models from jmad-modelpack-service')
46-
4737
class JMadModelPackService(object):
4838
def __init__(self, applicationContext):
4939
self._javaService = applicationContext['jmadModelPackageService']

pyjmad/pyjmad.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def range(self, range):
137137

138138
@property
139139
def strengths(self):
140-
return Strengths(self._jmadModel.getStrengthsAndVars())
140+
return Strengths(self._jmadModel)
141141

142142
@property
143143
def elements(self):
@@ -397,20 +397,24 @@ def __repr__(self):
397397

398398

399399
class Strengths(MutableMapping):
400-
def __init__(self, jmadStrengthVarSet):
401-
self._jmadStrengthVarSet = jmadStrengthVarSet
400+
def __init__(self, jmadModel):
401+
self._jmadStrengthVarSet = jmadModel.getStrengthsAndVars()
402+
self._jmadModel = jmadModel
402403

403-
def _jmadStrength(self, k):
404+
def __getitem__(self, k):
404405
jmadStrength = self._jmadStrengthVarSet.getStrength(k)
405406
if jmadStrength is None:
406407
raise KeyError('Invalid Strength Name: ' + k)
407-
return jmadStrength
408-
409-
def __getitem__(self, k):
410-
return self._jmadStrength(k).getValue()
408+
return jmadStrength.getValue()
411409

412410
def __setitem__(self, k, v):
413-
return self._jmadStrength(k).setValue(float(v))
411+
jmadStrength = self._jmadStrengthVarSet.getStrength(k)
412+
if jmadStrength is None:
413+
logging.info("Creating new MAD-X strength " + k)
414+
SimpleStrength = cern.accsoft.steering.jmad.domain.knob.strength.SimpleStrength
415+
jmadStrength = SimpleStrength(k, 0.0, None)
416+
jmadStrength.addListener(self._jmadModel.strengthListener)
417+
return jmadStrength.setValue(float(v))
414418

415419
def __delitem__(self, k):
416420
raise NotImplementedError('Deletion of Strengths is not supported')

pyjmad/spring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class SpringApplicationContext(object):
88
def __init__(self, configuration):
99
if type(configuration) is str:
10-
self._context = ClassPathXmlApplicationContext(configuration)
10+
self._context = ClassPathXmlApplicationContext([configuration])
1111
else:
12-
self._context = AnnotationConfigApplicationContext(configuration)
12+
self._context = AnnotationConfigApplicationContext([configuration])
1313

1414
def bean_definitions(self):
1515
return [str(s) for s in self._context.getBeanDefinitionNames()]

0 commit comments

Comments
 (0)