mirror of https://github.com/BURAI-team/burai.git
modify QEFXSlabEditorController
This commit is contained in:
parent
b22681c117
commit
f77abee700
|
@ -34,12 +34,16 @@ import burai.app.project.viewer.modeler.slabmodel.SlabModeler;
|
|||
import burai.atoms.model.Cell;
|
||||
import burai.atoms.vlight.AtomsVLight;
|
||||
import burai.com.consts.ConstantStyles;
|
||||
import burai.com.fx.FXBufferedThread;
|
||||
import burai.com.graphic.svg.SVGLibrary;
|
||||
import burai.com.graphic.svg.SVGLibrary.SVGData;
|
||||
import burai.com.keys.KeyNames;
|
||||
|
||||
public class QEFXSlabEditorController extends QEFXAppController {
|
||||
|
||||
private static final long SLEEP_SLAB_BUFFER = 300L;
|
||||
private static final long SLEEP_VACUUM_BUFFER = 150L;
|
||||
|
||||
private static final double CTRL_GRAPHIC_SIZE = 20.0;
|
||||
private static final String CTRL_GRAPHIC_CLASS = "piclight-button";
|
||||
|
||||
|
@ -79,9 +83,13 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
@FXML
|
||||
private TextField scaleField2;
|
||||
|
||||
private FXBufferedThread slabThread;
|
||||
|
||||
@FXML
|
||||
private Slider slabSlider;
|
||||
|
||||
private FXBufferedThread vacuumThread;
|
||||
|
||||
@FXML
|
||||
private Slider vacuumSlider;
|
||||
|
||||
|
@ -101,6 +109,9 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
this.projectController = projectController;
|
||||
|
||||
this.modeler = modeler;
|
||||
|
||||
this.slabThread = new FXBufferedThread(SLEEP_SLAB_BUFFER, true);
|
||||
this.vacuumThread = new FXBufferedThread(SLEEP_VACUUM_BUFFER, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,9 +121,9 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
this.setupCenterButton();
|
||||
this.setupCenterLabel();
|
||||
|
||||
this.setupSuperButton();
|
||||
this.setupScaleField(this.scaleField1);
|
||||
this.setupScaleField(this.scaleField2);
|
||||
this.setupSuperButton();
|
||||
|
||||
this.setupSlabSlider();
|
||||
this.setupVacuumSlider();
|
||||
|
@ -150,6 +161,14 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
this.modeler.initialize();
|
||||
}
|
||||
|
||||
if (this.scaleField1 != null) {
|
||||
this.scaleField1.setText(Integer.toString(SlabModel.defaultScale()));
|
||||
}
|
||||
|
||||
if (this.scaleField2 != null) {
|
||||
this.scaleField2.setText(Integer.toString(SlabModel.defaultScale()));
|
||||
}
|
||||
|
||||
if (this.slabSlider != null) {
|
||||
this.slabSlider.setValue(SlabModel.defaultThickness());
|
||||
}
|
||||
|
@ -195,7 +214,7 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
return;
|
||||
}
|
||||
|
||||
this.superButton.setDisable(true);
|
||||
this.superButton.setDisable(!this.isAvailSuper());
|
||||
this.superButton.getStyleClass().add(BUILD_GRAPHIC_CLASS);
|
||||
this.superButton.setGraphic(
|
||||
SVGLibrary.getGraphic(SVGData.GEAR, BUILD_GRAPHIC_SIZE, null, BUILD_GRAPHIC_CLASS));
|
||||
|
@ -218,11 +237,11 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
this.showErrorDialog();
|
||||
|
||||
if (this.scaleField1 != null) {
|
||||
this.scaleField1.setText("");
|
||||
this.scaleField1.setText(Integer.toString(this.modeler.getScaleA()));
|
||||
}
|
||||
|
||||
if (this.scaleField2 != null) {
|
||||
this.scaleField2.setText("");
|
||||
this.scaleField2.setText(Integer.toString(this.modeler.getScaleB()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -255,7 +274,8 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
return;
|
||||
}
|
||||
|
||||
textField.setText("");
|
||||
textField.setText(Integer.toString(SlabModel.defaultScale()));
|
||||
|
||||
textField.setStyle("");
|
||||
|
||||
textField.textProperty().addListener(o -> {
|
||||
|
@ -289,7 +309,7 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
String text = textField.getText();
|
||||
text = text == null ? null : text.trim();
|
||||
if (text == null || text.isEmpty()) {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
|
@ -308,14 +328,18 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
return;
|
||||
}
|
||||
|
||||
this.slabSlider.setValue(SlabModel.defaultThickness());
|
||||
|
||||
this.slabSlider.valueProperty().addListener(o -> {
|
||||
if (this.modeler == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double rate = this.slabSlider.getValue();
|
||||
rate = Math.max(rate, 0.1);
|
||||
this.modeler.changeSlabWidth(rate);
|
||||
|
||||
this.slabThread.runLater(() -> {
|
||||
this.modeler.changeSlabWidth(Math.max(rate, 0.0));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -324,14 +348,18 @@ public class QEFXSlabEditorController extends QEFXAppController {
|
|||
return;
|
||||
}
|
||||
|
||||
this.vacuumSlider.setValue(SlabModel.defaultVacuum());
|
||||
|
||||
this.vacuumSlider.valueProperty().addListener(o -> {
|
||||
if (this.modeler == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double vacuum = this.vacuumSlider.getValue();
|
||||
vacuum = Math.max(vacuum, 1.0);
|
||||
this.modeler.changeVacuumWidth(vacuum);
|
||||
|
||||
this.vacuumThread.runLater(() -> {
|
||||
this.modeler.changeVacuumWidth(Math.max(vacuum, 0.0));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,18 @@ import burai.atoms.model.Cell;
|
|||
|
||||
public abstract class SlabModel {
|
||||
|
||||
private static final double DEFAULT_OFFSET = 0.0;
|
||||
|
||||
private static final double DEFAULT_THICKNESS = 1.0;
|
||||
|
||||
private static final double DEFAULT_VACUUM = 10.0; // angstrom
|
||||
|
||||
private static final int DEFAULT_SCALE = 1;
|
||||
|
||||
public static double defaultOffset() {
|
||||
return DEFAULT_OFFSET;
|
||||
}
|
||||
|
||||
public static double defaultThickness() {
|
||||
return DEFAULT_THICKNESS;
|
||||
}
|
||||
|
@ -25,6 +33,10 @@ public abstract class SlabModel {
|
|||
return DEFAULT_VACUUM;
|
||||
}
|
||||
|
||||
public static int defaultScale() {
|
||||
return DEFAULT_SCALE;
|
||||
}
|
||||
|
||||
protected double offset;
|
||||
protected double thickness;
|
||||
protected double vacuum;
|
||||
|
@ -38,11 +50,11 @@ public abstract class SlabModel {
|
|||
private int lastScaleB;
|
||||
|
||||
protected SlabModel() {
|
||||
this.offset = 0.0;
|
||||
this.offset = DEFAULT_OFFSET;
|
||||
this.thickness = DEFAULT_THICKNESS;
|
||||
this.vacuum = DEFAULT_VACUUM;
|
||||
this.scaleA = 1;
|
||||
this.scaleB = 1;
|
||||
this.scaleA = DEFAULT_SCALE;
|
||||
this.scaleB = DEFAULT_SCALE;
|
||||
|
||||
this.lastOffset = this.offset;
|
||||
this.lastThickness = this.thickness;
|
||||
|
@ -55,22 +67,42 @@ public abstract class SlabModel {
|
|||
this.offset = offset;
|
||||
}
|
||||
|
||||
protected final double getOffset() {
|
||||
return this.offset;
|
||||
}
|
||||
|
||||
public final void setThickness(double thickness) {
|
||||
this.thickness = thickness;
|
||||
}
|
||||
|
||||
protected final double getThickness() {
|
||||
return this.thickness;
|
||||
}
|
||||
|
||||
public final void setVacuum(double vacuum) {
|
||||
this.vacuum = vacuum;
|
||||
}
|
||||
|
||||
protected final double getVacuum() {
|
||||
return this.vacuum;
|
||||
}
|
||||
|
||||
public final void setScaleA(int scaleA) {
|
||||
this.scaleA = scaleA;
|
||||
}
|
||||
|
||||
protected final int getScaleA() {
|
||||
return this.scaleA;
|
||||
}
|
||||
|
||||
public final void setScaleB(int scaleB) {
|
||||
this.scaleB = scaleB;
|
||||
}
|
||||
|
||||
protected final int getScaleB() {
|
||||
return this.scaleB;
|
||||
}
|
||||
|
||||
public abstract SlabModel[] getSlabModels();
|
||||
|
||||
protected abstract boolean updateCell(Cell cell);
|
||||
|
|
|
@ -37,6 +37,8 @@ public class SlabModelStem extends SlabModel {
|
|||
private static final String STOIX_NATOM = "NAtom";
|
||||
|
||||
private static final double STEP_FOR_GENOMS = 0.5; // angstrom
|
||||
private static final double STEP_FOR_CTHICK = 0.05; // internal coordinate
|
||||
private static final int MAX_FOR_CTHICK = 20;
|
||||
|
||||
private int miller1;
|
||||
private int miller2;
|
||||
|
@ -516,91 +518,97 @@ public class SlabModelStem extends SlabModel {
|
|||
return false;
|
||||
}
|
||||
|
||||
double cThick = 1.0;
|
||||
if (slabModel.thickness > 0.0) {
|
||||
cThick = slabModel.thickness;
|
||||
}
|
||||
double cThick = Math.max(0.0, slabModel.thickness);
|
||||
|
||||
if (this.lattAuxi[2][2] * Math.abs(cThick - 1.0) > THICK_THR) {
|
||||
this.entryAuxi = new ArrayList<AtomEntry>();
|
||||
} else {
|
||||
this.entryAuxi = this.entryUnit;
|
||||
}
|
||||
for (int istep = 0; istep < MAX_FOR_CTHICK; istep++) {
|
||||
|
||||
int nThick = (int) (Math.ceil(cThick) + 0.1);
|
||||
|
||||
for (int iThick = 0; iThick < nThick; iThick++) {
|
||||
List<AtomEntry> entryBuffer = null;
|
||||
Map<String, Double> stoixBuffer = null;
|
||||
if (iThick == (nThick - 1)) {
|
||||
entryBuffer = new ArrayList<AtomEntry>();
|
||||
stoixBuffer = new HashMap<String, Double>();
|
||||
if (this.lattAuxi[2][2] * Math.abs(cThick - 1.0) > THICK_THR) {
|
||||
this.entryAuxi = new ArrayList<AtomEntry>();
|
||||
} else {
|
||||
this.entryAuxi = this.entryUnit;
|
||||
}
|
||||
|
||||
for (AtomEntry entry : this.entryUnit) {
|
||||
if (entry == null) {
|
||||
continue;
|
||||
int nThick = (int) (Math.ceil(cThick) + 0.1);
|
||||
|
||||
for (int iThick = 0; iThick < nThick; iThick++) {
|
||||
List<AtomEntry> entryBuffer = null;
|
||||
Map<String, Double> stoixBuffer = null;
|
||||
if (iThick == (nThick - 1)) {
|
||||
entryBuffer = new ArrayList<AtomEntry>();
|
||||
stoixBuffer = new HashMap<String, Double>();
|
||||
}
|
||||
|
||||
String name = entry.name;
|
||||
if (name == null || name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (AtomEntry entry : this.entryUnit) {
|
||||
if (entry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double a = entry.a;
|
||||
double b = entry.b;
|
||||
double c = entry.c + slabModel.offset;
|
||||
c -= Math.floor(c);
|
||||
String name = entry.name;
|
||||
if (name == null || name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double dc = Math.abs(c - 1.0);
|
||||
double dz = dc * this.lattAuxi[2][2];
|
||||
if (dz < POSIT_THR) {
|
||||
c -= 1.0;
|
||||
}
|
||||
double a = entry.a;
|
||||
double b = entry.b;
|
||||
double c = entry.c + slabModel.offset;
|
||||
c -= Math.floor(c);
|
||||
|
||||
c -= (double) iThick;
|
||||
double dc = Math.abs(c - 1.0);
|
||||
double dz = dc * this.lattAuxi[2][2];
|
||||
if (dz < POSIT_THR) {
|
||||
c -= 1.0;
|
||||
}
|
||||
|
||||
dc = c - (1.0 - cThick);
|
||||
dz = dc * this.lattAuxi[2][2];
|
||||
if (dz < (-2.0 * POSIT_THR)) {
|
||||
continue;
|
||||
}
|
||||
c -= (double) iThick;
|
||||
|
||||
AtomEntry entry2 = null;
|
||||
if (this.entryAuxi != this.entryUnit) {
|
||||
entry2 = new AtomEntry(this.lattAuxi);
|
||||
} else {
|
||||
entry2 = entry;
|
||||
}
|
||||
|
||||
entry2.name = name;
|
||||
entry2.x = a * this.lattAuxi[0][0] + b * this.lattAuxi[1][0] + c * this.lattAuxi[2][0];
|
||||
entry2.y = a * this.lattAuxi[0][1] + b * this.lattAuxi[1][1] + c * this.lattAuxi[2][1];
|
||||
entry2.z = a * this.lattAuxi[0][2] + b * this.lattAuxi[1][2] + c * this.lattAuxi[2][2];
|
||||
|
||||
if (this.entryAuxi != this.entryUnit) {
|
||||
if (iThick < (nThick - 1)) {
|
||||
this.entryAuxi.add(entry2);
|
||||
dc = c - (1.0 - cThick);
|
||||
dz = dc * this.lattAuxi[2][2];
|
||||
if (dz < (-2.0 * POSIT_THR)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AtomEntry entry2 = null;
|
||||
if (this.entryAuxi != this.entryUnit) {
|
||||
entry2 = new AtomEntry(this.lattAuxi);
|
||||
} else {
|
||||
entryBuffer.add(entry2);
|
||||
entry2 = entry;
|
||||
}
|
||||
|
||||
entry2.name = name;
|
||||
entry2.x = a * this.lattAuxi[0][0] + b * this.lattAuxi[1][0] + c * this.lattAuxi[2][0];
|
||||
entry2.y = a * this.lattAuxi[0][1] + b * this.lattAuxi[1][1] + c * this.lattAuxi[2][1];
|
||||
entry2.z = a * this.lattAuxi[0][2] + b * this.lattAuxi[1][2] + c * this.lattAuxi[2][2];
|
||||
|
||||
if (this.entryAuxi != this.entryUnit) {
|
||||
if (iThick < (nThick - 1)) {
|
||||
this.entryAuxi.add(entry2);
|
||||
|
||||
stoixBuffer.put(STOIX_NATOM, (double) entryBuffer.size());
|
||||
if (stoixBuffer.containsKey(name)) {
|
||||
double value = stoixBuffer.get(name);
|
||||
stoixBuffer.put(name, value + 1.0);
|
||||
} else {
|
||||
stoixBuffer.put(name, 1.0);
|
||||
}
|
||||
entryBuffer.add(entry2);
|
||||
|
||||
if (this.stoixUnit != null && this.equalsStoichiometry(this.stoixUnit, stoixBuffer)) {
|
||||
this.entryAuxi.addAll(entryBuffer);
|
||||
entryBuffer.clear();
|
||||
stoixBuffer.clear();
|
||||
stoixBuffer.put(STOIX_NATOM, (double) entryBuffer.size());
|
||||
if (stoixBuffer.containsKey(name)) {
|
||||
double value = stoixBuffer.get(name);
|
||||
stoixBuffer.put(name, value + 1.0);
|
||||
} else {
|
||||
stoixBuffer.put(name, 1.0);
|
||||
}
|
||||
|
||||
if (this.stoixUnit != null && this.equalsStoichiometry(this.stoixUnit, stoixBuffer)) {
|
||||
this.entryAuxi.addAll(entryBuffer);
|
||||
entryBuffer.clear();
|
||||
stoixBuffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.entryAuxi.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
cThick += STEP_FOR_CTHICK;
|
||||
}
|
||||
|
||||
if (this.entryAuxi.size() >= ModelerBase.maxNumAtoms()) {
|
||||
|
|
|
@ -26,8 +26,28 @@ public class SlabModeler extends ModelerBase {
|
|||
this.slabModel = slabModel;
|
||||
}
|
||||
|
||||
public double getOffset() {
|
||||
return this.slabModel == null ? SlabModel.defaultOffset() : this.slabModel.getOffset();
|
||||
}
|
||||
|
||||
public double getThickness() {
|
||||
return this.slabModel == null ? SlabModel.defaultThickness() : this.slabModel.getThickness();
|
||||
}
|
||||
|
||||
public double getVacuum() {
|
||||
return this.slabModel == null ? SlabModel.defaultVacuum() : this.slabModel.getVacuum();
|
||||
}
|
||||
|
||||
public int getScaleA() {
|
||||
return this.slabModel == null ? SlabModel.defaultScale() : this.slabModel.getScaleA();
|
||||
}
|
||||
|
||||
public int getScaleB() {
|
||||
return this.slabModel == null ? SlabModel.defaultScale() : this.slabModel.getScaleB();
|
||||
}
|
||||
|
||||
public boolean changeSlabWidth(double rate) {
|
||||
if (rate <= 0.0) {
|
||||
if (rate < 0.0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -80,7 +100,7 @@ public class SlabModeler extends ModelerBase {
|
|||
}
|
||||
|
||||
public boolean changeVacuumWidth(double vacuum) {
|
||||
if (vacuum <= 0.0) {
|
||||
if (vacuum < 0.0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue