-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4554 - Support variant monomers in Ketcher (flex mode)
- added variant monomers to model/view and deserialization
- Loading branch information
1 parent
2b898c6
commit f0c324b
Showing
20 changed files
with
484 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
packages/ketcher-core/src/application/render/renderers/ChemRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
packages/ketcher-core/src/application/render/renderers/PeptideRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
packages/ketcher-core/src/application/render/renderers/PhosphateRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
packages/ketcher-core/src/application/render/renderers/RNABaseRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
packages/ketcher-core/src/application/render/renderers/SugarRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/ketcher-core/src/application/render/renderers/VariantMonomerRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Selection } from 'd3'; | ||
import { BaseMonomerRenderer } from 'application/render/renderers/BaseMonomerRenderer'; | ||
import { VariantMonomer } from 'domain/entities/VariantMonomer'; | ||
import { MONOMER_SYMBOLS_IDS } from 'application/render/renderers/constants'; | ||
|
||
const NUMBER_OF_MONOMERS_CIRCLE_RADIUS = 3; | ||
const NUMBER_OF_MONOMERS_CIRCLE_Y_OFFSET = 7; | ||
|
||
export class VariantMonomerRenderer extends BaseMonomerRenderer { | ||
private monomerSymbolElementsIds: { | ||
selected: string; | ||
hover: string; | ||
body: string; | ||
variant?: string; | ||
}; | ||
|
||
constructor(public monomer: VariantMonomer, scale?: number) { | ||
const monomerClass = VariantMonomer.getMonomerClass(monomer.monomers); | ||
const monomerSymbolElementsIds = MONOMER_SYMBOLS_IDS[monomerClass]; | ||
|
||
super( | ||
monomer, | ||
monomerSymbolElementsIds.selected, | ||
monomerSymbolElementsIds.hover, | ||
monomerSymbolElementsIds.body, | ||
scale, | ||
); | ||
|
||
this.monomerSymbolElementsIds = monomerSymbolElementsIds; | ||
} | ||
|
||
protected appendBody( | ||
rootElement: Selection<SVGGElement, void, HTMLElement, never>, | ||
) { | ||
return rootElement | ||
.append('use') | ||
.data([this]) | ||
.attr( | ||
'href', | ||
this.monomerSymbolElementsIds.variant || | ||
this.monomerSymbolElementsIds.body, | ||
) | ||
.attr('fill', '#fff') | ||
.attr('stroke', '#585858') | ||
.attr('stroke-width', '1px') | ||
.attr('paint-order', 'fill'); | ||
} | ||
|
||
protected get enumerationElementPosition() { | ||
return undefined; | ||
} | ||
|
||
protected get beginningElementPosition() { | ||
return undefined; | ||
} | ||
|
||
private appendNumberOfMonomers() { | ||
const numberOfMonomersElement = this.rootElement | ||
?.append('g') | ||
.attr( | ||
'transform', | ||
`translate(${this.center.x - this.scaledMonomerPosition.x}, ${ | ||
this.center.y - | ||
this.scaledMonomerPosition.y + | ||
NUMBER_OF_MONOMERS_CIRCLE_Y_OFFSET | ||
})`, | ||
) | ||
.attr('pointer-events', 'none'); | ||
|
||
numberOfMonomersElement | ||
?.append('circle') | ||
.attr('cx', 0) | ||
.attr('cy', 0) | ||
.attr('r', NUMBER_OF_MONOMERS_CIRCLE_RADIUS) | ||
.attr('fill', '#fff') | ||
.attr('stroke', '#CCEAEE') | ||
.attr('stroke-width', 0.5); | ||
|
||
numberOfMonomersElement | ||
?.append('text') | ||
.attr('x', -1.6) | ||
.attr('y', 2.1) | ||
.attr('font-size', '6px') | ||
.attr('font-weight', 300) | ||
.text(this.monomer.monomers.length); | ||
} | ||
|
||
public show(theme) { | ||
super.show(theme); | ||
this.appendNumberOfMonomers(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/ketcher-core/src/application/render/renderers/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { KetMonomerClass } from 'application/formatters'; | ||
|
||
export const MONOMER_SYMBOLS_IDS = { | ||
[KetMonomerClass.AminoAcid]: { | ||
hover: '#peptide-hover', | ||
selected: '#peptide-selection', | ||
body: '#peptide', | ||
}, | ||
[KetMonomerClass.CHEM]: { | ||
hover: '#chem-selection', | ||
selected: '#chem-selection', | ||
body: '#chem', | ||
}, | ||
[KetMonomerClass.Sugar]: { | ||
hover: '#sugar-selection', | ||
selected: '#sugar-selection', | ||
body: '#sugar', | ||
}, | ||
[KetMonomerClass.Base]: { | ||
hover: '#rna-base-selection', | ||
selected: '#rna-base-selection', | ||
body: '#rna-base', | ||
variant: '#rna-base-variant', | ||
}, | ||
[KetMonomerClass.Phosphate]: { | ||
hover: '#phosphate-selection', | ||
selected: '#phosphate-selection', | ||
body: '#phosphate', | ||
}, | ||
[KetMonomerClass.RNA]: { | ||
hover: '#nucleotide-hover', | ||
selected: '#nucleotide-selection', | ||
body: '#nucleotide', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.